joyent/node — Issue #2310: optionally shim into "Error" and add additional data to it
Author: thejh
Created: 2011-12-09 23:02:18+00:00
State: open

Hello,
I just had an idea that I think of that it might be feasible as soon as we have V8 isolates available in node. It's not easy to do, but I think that it'd make finding errors much easier because you wouldn't even have to fire up a debugger. Also, you'd even get variables from callback parent scopes which you usually can't see in a regular debugger.

If you call node with a special switch, it opens a debug port and spawns a new isolate that connects to it. When an `Error` gets created in node, a breakpoint inside the `Error` constructor kicks in. The isolate receives the "breakpoint hit" event and collects some debug data from the stack, e.g. the types of all variables and maybe also `util.inspect` representations of them, on all levels. Then, it scans all stack frames for callbacks, puts breakpoints into the callbacks and calls them without arguments (maybe live-patching them before to prevent their actual contents from being run? - not sure whether this would work the way I think). On each breakpoint in such a callback, it collects all variable types and such things again. This happens recursively. When all the work is done, you have a pretty clear image of what was going on when the Error object was created. Now the debugger isolate can attach all that data to the `Error` and let the master isolate continue crashing.