process: improve stack trace on async(libuv) error
Checklist
-
make -j4 test
(UNIX), orvcbuild test nosign
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines
Affected core subsystem(s)
process
Description of change
This patch saves the stack into TickObject
by calling Error.captureStackTrace()
, and will append those stacks if something went wrong.
For example:
require('child_process').spawn('error factory');
will throw:
Error: spawn error factory ENOENT
at exports._errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
at onErrorNT (internal/child_process.js:348:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
but with this change, we will see the following:
internal/process/next_tick.js:102
throw err;
^
Error: spawn error factory ENOENT
at exports._errnoException (util.js:1026:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:99:11)
at Module.runMain (module.js:592:11)
at run (bootstrap_node.js:382:7)
at startup (bootstrap_node.js:137:9)
at bootstrap_node.js:497:3
at process.nextTick (internal/process/next_tick.js:160:24)
at ChildProcess.spawn (internal/child_process.js:296:13)
at Object.exports.spawn (child_process.js:385:9)
at Object.<anonymous> (/Users/yorkieliu/workspace/test-process-next-tick.js:2:26)
.......<more stack>
This would help developer to track what happened when some async callbacks are thrown, mostly are syscall error.
But to be noted that, this adds a possible unneeded .stack
field to every TickObject
and catch
every call to callback
. Both are hurting the perf in huge I guess. I'm not sure if we could land this, but I think the feature really saves time when debugging Node.js programs, perhaps an (CLI/API) option from user-land could be the way to go