-
-
Notifications
You must be signed in to change notification settings - Fork 657
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
fix(core): improve error handling with multiple errors in flashCallbacks #3011
fix(core): improve error handling with multiple errors in flashCallbacks #3011
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
@dmaskasky What do you think? |
commit: |
|
Playground | Link |
---|---|
React demo | https://livecodes.io?x=id/DUVV6M8JJ |
See documentations for usage instructions.
src/vanilla/internals.ts
Outdated
|
||
if (errors.length === 1) { | ||
throw errors[0] | ||
} else if (errors.length > 1) { | ||
throw new AggregateError( | ||
errors, | ||
'Multiple errors occurred during flushCallbacks', | ||
) |
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 would even go with this. Not sure about the drawback, but it's predictable.
if (errors.length === 1) { | |
throw errors[0] | |
} else if (errors.length > 1) { | |
throw new AggregateError( | |
errors, | |
'Multiple errors occurred during flushCallbacks', | |
) | |
if (errors.length) { | |
throw new AggregateError(errors) |
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.
@dai-shi I think it's good way to go!
I'd change commit with it and force-push, thanks!
- done
Previously, only the first error was thrown and subsequent errors were ignored. Now all errors are collected and: - If there's only one error, throw it directly - If there are multiple errors, throw them as AggregateError This change improves debugging by preserving all error information during callback execution. Co-authored-by: daishi <[email protected]>
6e45368
to
310a58b
Compare
My main concern is that AggregateError will not pass an instance check.
Are there examples where AggregateError is used in other open source libraries? |
Reading more on AggregateError, I think this makes sense. Could we do if (errors.length === 1) {
throw errors[0]
} else if (errors.length) {
throw new AggregateError(errors)
} |
I don't think it's solved anyways, because you don't know if other subscribers throw an 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.
I like this all-or-nothing approach. It's more predictable.
Should we wrap all errors in AggregateError? Is this something we should teach? |
Yes, that's exactly my suggestion. It's harder to tell when it's wrapped otherwise. |
Related Bug Reports or Discussions
Fixes #
Summary
Previously, only the first error was thrown and subsequent errors were ignored. Now all errors are collected and:
This change improves debugging by preserving all error information during callback execution.
Check List
pnpm run fix
for formatting and linting code and docs