Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/BleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,16 @@ export class BleManager {

if (emitCurrentState) {
var cancelled = false
this._callPromise(this.state()).then(currentState => {
if (!cancelled) {
listener(currentState)
this._callPromise(this.state()).then(
currentState => {
if (!cancelled) {
listener(currentState)
}
},
() => {
// Prevent unhandled promise rejection for internal state fetch.
}
Comment on lines +325 to 327
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.
})
)

wrappedSubscription = {
remove: () => {
Expand Down
Loading