asap
asap copied to clipboard
Usability in development mode with thrown errors
Evidently, at least in recent Chrome, errors that are captured and released asynchronously lose their stack traces.
Options to mitigate this would include at least:
- rework how we deal with errors, allowing errors to pass through synchronously after we request another flush, at least in development mode if not in production as well, at the expense of the performance and priority of flushing a queue with uncaught exceptions.
- find a way to capture the stack trace on the error before deferring. preliminary attempts failed.
- …
cc @rkatic
I noticed this recently as well. It seems like a bug in the chrome dev tools: if I put a breakpoint where the error is being re-thrown and inspect err.stack
manually I get the correct value.
Need to produce an isolated case and send it to Chromium https://code.google.com/p/chromium/issues/list
But will also have to work around the problem here, for now.
I'm not sure if hacking around the problem here will be of much use to most promise libraries. I suspect it will only fix the problem in certain isolated cases.
Attempts to isolate have so far been in vain.
I created a bundle from the following and it did not exhibit the missing stack trace problem in Chrome dev tools.
var asap = require('./asap');
asap(function () {
throw new Error('Fake');
});
I also tried this stand-alone, gradually adding complications without being able to reproduce the problem:
var pendingErrors = [];
function requestThrow() {
setTimeout(rethrow);
}
function rethrow() {
throw pendingErrors.shift();
}
function stackFrame() {
try {
indirection();
} catch (error) {
pendingErrors.push(error);
requestThrow();
} finally {
}
}
function indirection() {
throw new Error("Example");
}
setTimeout(function () {
stackFrame();
}, 100);
So there appears to be an exogenous factor.
We could always add an asap.forceSyncThrow
. Finding a workaround for this issue could be difficult and unreliable. I'm willing to investigate more on this, but this month I will still probably not have much free time.