-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked parts of internal error handling (#4145)
* Do not swallow errors * Add test for #4004 * WIP fix tests? * skip the unhandled rejection test * wrap observer calls with reportUnhandledError * move towards status unification * update test * roll back status changes * add comment to reportUnhandledError * make sure that root reports errors with no subscribers * tweak the logic * avoid rethrowing * add more coverage * remove redundant timeout * Changeset * Update .changeset/chilled-bobcats-lay.md Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com> --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
1 parent
231a6f3
commit 5cc9025
Showing
18 changed files
with
799 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
Significant improvements to error handling have been made: | ||
|
||
- Actors will no longer crash when an error is thrown in an observer (`actor.subscribe(observer)`). | ||
- Errors will be handled by observer's `.error()` handler: | ||
```ts | ||
actor.subscribe({ | ||
error: (error) => { | ||
// handle error | ||
} | ||
}); | ||
``` | ||
- If an observer does not have an error handler, the error will be thrown in a clear stack so bug tracking services can collect it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* This function makes sure that unhandled errors are thrown in a separate macrotask. | ||
* It allows those errors to be detected by global error handlers and reported to bug tracking services | ||
* without interrupting our own stack of execution. | ||
* | ||
* @param err error to be thrown | ||
*/ | ||
export function reportUnhandledError(err: unknown) { | ||
setTimeout(() => { | ||
throw err; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.