question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Throwing from async actions and effects causes uncaught errors (even when those are explicitly caught) - React

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
christianalfonicommented, Jun 7, 2020

Thanks a bunch for the example! Will look at this for next release! 😄

0reactions
christianalfonicommented, Jun 18, 2020

Closing this for now as it will be part of next release 😄

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found