Before, I used async.js
with callbacks to make a webapp. It worked very nicely -- when an error would occur, I'd get the whole stack pointing exactly to the line where the error happened.
Now, when I'm trying the same with async/await
in Node's harmony mode, the errors only point to the last catch blocks. Example:
try {
await goDoSomething();
} catch (e) {
console.error(e);
}
Now, goDoSomething
will do some async action, like pull from database, and then a bunch of synchronous code, like process the records, etc.
If an error happens in that synchronous code that processes records, the stack will point to the catch block of the code above (and not the actual line where the error happened).
This is insanely difficult to debug. Which leaves me with the assumption that I should have these try/catch
blocks multiple times throughout all of my code (even synchronous stuff)...?
What am I missing? How do I have normal and accurate error catching with async/await
?
via John Derring
No comments:
Post a Comment