Skip to content

Commit 5bc34d3

Browse files
Fix unhandledRejection handler: tighten pattern match, use nextTick for rethrow
- Use /request with tag.*timed out/ regex instead of .includes('timed out') to avoid suppressing unrelated timeout errors from other sources - Use process.nextTick(() => { throw reason }) instead of bare throw inside the handler so non-lutron-leap rejections reliably crash the process (in Node.js 15+, throw inside unhandledRejection re-emits rather than exits) Agent-Logs-Url: https://github.com/homebridge-plugins/homebridge-lutron/sessions/1d73447e-e125-477e-9d72-433b89c8167f Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
1 parent fb03b9f commit 5bc34d3

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/Platform.HAP.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,17 @@ export class LutronCasetaLeap
158158
return
159159
}
160160
// lutron-leap LeapClient request timeout (an Error with a known message pattern)
161-
if (reason instanceof Error && reason.message.includes('timed out')) {
161+
if (reason instanceof Error && /request with tag.*timed out/.test(reason.message)) {
162162
this.log.debug('Suppressed lutron-leap request timeout (unhandled rejection):', reason.message)
163163
return
164164
}
165-
// Unknown unhandled rejection — re-throw so Node.js handles it as fatal.
166-
// This preserves the default crash behaviour for any rejection that is not
167-
// a known lutron-leap artefact, preventing silent data loss.
165+
// Unknown unhandled rejection — schedule a throw on the next tick so
166+
// Node.js handles it as a fatal uncaught exception. Throwing directly
167+
// inside the 'unhandledRejection' handler in Node.js 15+ causes a
168+
// second unhandledRejection event rather than a process exit, so we
169+
// use process.nextTick() to break out of the handler's call stack.
168170
this.log.warn('Unhandled promise rejection (not a known lutron-leap timeout):', reason)
169-
throw reason
171+
process.nextTick(() => { throw reason })
170172
})
171173
}
172174

0 commit comments

Comments
 (0)