[BUG] Throwing from async actions and effects causes uncaught errors (even when those are explicitly caught) - React
See original GitHub issueHello,
minimal codesandbox example here - https://codesandbox.io/s/overmind-example-toloe?file=/src/components/App.js . The core of the issue is as follows:
// in component
useEffect(() => {
// the error is correctly caught here but also propagates as unhandled
new Promise((resolve, reject) => {
// if I throw directly from here I'll only get the console log from catch clause
// throw new Error('uncomment to see correct behaviour')
// if thrown from action I'll get the react overlay
actions.exampleAction().catch(e => reject(e));
}).catch(e => console.log(e));
}, [actions]);
// overmind/index.js
export const config = {
actions: {
// if the action is sync all is well
exampleAction: async ({ state, effects }) => {
throw new Error("hello");
// same behaviour when throwing from effects, whether awaited or not
// effects.test();
}
},
effects: {
// when sync all is good, adding async keyword seems to break this ?
test: async () => {
throw new Error("hello");
}
}
};
This might be related to https://github.com/cerebral/overmind/issues/318 but the behaviour is slightly different - the error actually gets caught by the catch clause, but somehow it also propagates as unhandled. I’m also not sure if this may be related to React, the original issue was for Vue.
Thanks for the reply and for the library as well. Cheers.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Catching Asynchronous Errors in React using Error Boundaries
If we run this code, the ErrorBoundary will catch the error, render the fallback UI (Something went wrong) and log the error to...
Read more >React Hook Warnings for async function in useEffect
The reason React doesn't automatically allow async functions in useEffect is that in a huge portion of cases, there is some cleanup necessary....
Read more >Improving TypeScript error handling with exhaustive type ...
Discover an improved method for handling errors in TypeScript that solves problems that arise from returning null and throwing try...catch.
Read more >Error handling with async/await and promises, n² ... - CatchJS
Async await error handling has a bunch of edge cases. ... Will not catch errors thrown in another call stack via a setTimeout()...
Read more >A Definitive Guide to Handling Errors in JavaScript - Kinsta
These objects contain ample information about the type of the error, the statement that caused the error, and the stack trace when the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks a bunch for the example! Will look at this for next release! 😄
Closing this for now as it will be part of next release 😄