Skip to content

fix: prevent unhandled promise rejection when fetching state#1330

Merged
aliberski merged 1 commit intomasterfrom
fix/1315
Mar 9, 2026
Merged

fix: prevent unhandled promise rejection when fetching state#1330
aliberski merged 1 commit intomasterfrom
fix/1315

Conversation

@aliberski
Copy link
Collaborator

Adds a rejection handler to the internal state fetch when a listener is attached to avoid potential unhandled promise rejections.

Fixes #1315

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an unhandled promise rejection that was reported in issue #1307, where the internal state fetch inside onStateChange (when called with emitCurrentState: true) could throw a BleError that was not caught, causing Sentry and other error tracking tools to surface it as an unhandled promise rejection even when users had their own error handlers.

Changes:

  • Converts the fire-and-forget .then(successCb) call on the internal this.state() promise to .then(successCb, rejectionCb) with an empty rejection handler, preventing the unhandled promise rejection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +325 to 327
() => {
// Prevent unhandled promise rejection for internal state fetch.
}
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no test covering the emitCurrentState: true path in onStateChange, and in particular no test verifying that when the internal state fetch rejects, the promise rejection is swallowed and does not propagate (the core behavior this fix adds). The existing test at line 106 only exercises the emitCurrentState: false (default) code path. Given that the rest of BleManager.js is thoroughly covered and the whole purpose of this PR is to prevent an unhandled rejection, a test ensuring this behavior works correctly (e.g. mocking BleModule.state to reject and asserting no unhandled rejection is thrown) would be valuable.

Copilot uses AI. Check for mistakes.
@aliberski aliberski merged commit 92a496d into master Mar 9, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Question: BleErrors being captured by Sentry even when caught

2 participants