3 ms·
Stack traces for async code are always borderline useless in Javascript. Instead of telling me who called the offending code it just informs me that the code is
by wongarsu 8y ago
Stack traces for async code are always borderline useless in Javascript. Instead of telling me who called the offending code it just informs me that the code is executed by an scheduler in the event loop.
- z3t4 8y agoYou create the error before doing the async operation, then throw/callback that error with additional info from the async error.
- wongarsu 8y agoThat sounds tedious in a web server where like half the functions are async. Also why is that my responsibility? A stack trace is supposed to show the call chain, not language implementation details. At a minimum `async x()` should just be equivalent to `try { async x() } catch(err) { throw new Error(err) }` (with the logger printing all nested exceptions)
- z3t4 8y agoMost of the time you will get the correct call chain, so you only have to do this rarely.
- slaymaker1907 8y agoOne feature of CUDA that is nice is that while you can use streams to do stuff asynchronously, you can make it synchronous for easier debugging by setting a flag. Unfortunately, I don’t think something like this is possible with JS promises since new Promise() is guaranteed to execute in a different iteration of the event loop.
- vimslayer 8y agoAre you transpiling your async functions away? IIRC there's been a lot of work on async function stack traces in V8 but it's obviously useless if they are compiled to some state machine monstrosoty before getting executed.