Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error from catch is not defined when debugging

I have a promise that is rejected with an error and I'm using try/catch to handle it.

const foo = async () => {
  try {
    await request();
  } catch (error) {
    console.log(error.message);
    debugger;
  }
};

When debugging, the console.log shows the correct error but if I pass the mouse over it shows that error is not defined.

enter image description here

Why this is happening?

This is making the debugging of errors really hard.

Here is a working example

like image 308
Vencovsky Avatar asked Aug 16 '26 07:08

Vencovsky


1 Answers

My workarround is to assign the error to a variable, it is possible to debug this variable.

const foo = async () => {
  try {
    await request();
  } catch (error) {
    let myError = error; // <--myError is visible in the debugger!!!    
    console.log(error.message);
    debugger;
  }
};
like image 166
christofvanhove Avatar answered Aug 17 '26 22:08

christofvanhove



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!