Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle error events on xkeys that can be emitted during the init process before the instance is exposed for listener registration #113

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

loucadufault
Copy link
Contributor

Fixes #112 (implements the first approach discussed)

…ess before the instance is exposed for listener registration
.finally(() => (alreadyRejected = true))
}
// Handle all error events until the instance is returned
xkeys.on('error', xkeysStopgapErrorHandler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't use once intentionally. Until we have resolved back the instance to the caller, we are responsible to keep catching errors that may be emitted.

@loucadufault
Copy link
Contributor Author

Implementation could be revised with the addition of a flush method as discussed here.

Copy link
Member

@nytamin nytamin left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! I agree, this should handle the edge case where an error event is emitted during initialization.

Note to self: When merging this, add a equivalent handling to setupXKeysPanel in the node-package.

return
}
deviceWrap.close()
.then(() => reject())
Copy link
Member

Choose a reason for hiding this comment

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

Minor note: is there a reason the reject() has no argument here? Should we reject(e)?

Copy link
Contributor Author

@loucadufault loucadufault Dec 4, 2024

Choose a reason for hiding this comment

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

This is for the path where deviceWrap.close() promise resolves, where it should resolve to a void promise, but still I want to avoid forwarding whatever value it resolves to as the rejected value of the enclosing (returned) promise in case the API of that method changes.

@loucadufault
Copy link
Contributor Author

loucadufault commented Dec 4, 2024

I added an implementation for node in #114.

I also simplified the implementation here and there to not handle the cleanup inside the promise executor, and instead rely on the existing catch clause which execution will break out to if the promise rejects.

@loucadufault loucadufault requested a review from nytamin December 4, 2024 14:45
.close()
.then(() => reject())
.catch(reject)
.finally(() => (alreadyRejected = true))
Copy link
Contributor Author

@loucadufault loucadufault Dec 4, 2024

Choose a reason for hiding this comment

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

doing this in the finally (old implementation) was not semantically coherent since the flag only makes sense when the promise rejects, not when it resolves (same applies below). So changed this.

@nytamin nytamin merged commit 193eb78 into SuperFlyTV:master Dec 5, 2024
6 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.

setupXkeysPanel WebHID method emits uncatchable error
2 participants