-
Notifications
You must be signed in to change notification settings - Fork 12
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
Enable eslint rule and reject with errors instead of strings #42
Enable eslint rule and reject with errors instead of strings #42
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason
property of an AbortSignal
can actually be an Error
.
Consider the difference between:
const ac = new AbortController();
ac.signal.addEventListener('abort', function () { console.log(this.reason.constructor, this.reason); })
ac.abort();
…and…
const ac = new AbortController();
ac.signal.addEventListener('abort', function () { console.log(this.reason.constructor, this.reason); })
ac.abort('o no');
reason
is a DOMException
in the first, and a String
in the second.
I think there are only two ways forward here:
- Leave this as is, suppress the lint.
- If the
reason
istypeof string
then wrap it in anError
. Otherwise, reject withreason
directly.
I think the second raises more questions than it answers, so I'm inclined to do the first.
a6715b3
to
f59b494
Compare
Following your concerns and for simplicity, I suppressed the lints and introduced Errors inside of a test and an example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think the Error
conversions need to go.
f59b494
to
204f681
Compare
Sorry about that. I took a deeper look into the AbortController and AbortSignal and you are right about it. It doesn't make sense to wrap it in an extra Error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving our code quality!
Following #13 , this PR intends to enable the eslint rule:
prefer-promise-reject-errors
as error.I believe that treating promise rejections as errors ensures better handling and propagation of the rejection reason to the final components. The affected package tests have been updated accordingly.