We have an issue with the Q formatting of the stack trace - its not
playing well with our stack-trace manipulation.
When we have an unhandled error - and end() throws it, the resultant
stacktrace is unreadable.
To improve our error reporting we have a NestedError.
Which looks like this:
function NestedError(message, cause) {
this.constructor.prototype.__proto__ = Error.prototype;
this.name =
this.constructor.name;
this.message = message;
this.cause = cause;
Error.captureStackTrace(this, this.constructor);
if (cause) {
var causeDetail = _.isString(cause) ? cause :
util.inspect(cause);
this.stack += "\n Caused by : " + (cause.stack ? cause.stack :
causeDetail) + "\n";
}
}
And when we get an error like : new NestedError("BANG!", new
Error("CRASH!"));
The stack trace looks like this :
NestedError: BANG!
at Object.module.exports.doSomething (E:\dev\projects\moo\server
\test\errors-test.js:60:30)
at Object.wrapTest (E:\dev\projects\moo\test\dep\node_modules
\nodeunit\lib\core.js:235:16)
at wrapTest (E:\dev\projects\moo\test\dep\node_modules\nodeunit\lib
\core.js:235:16)
at Object.exports.runTest (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\lib\core.js:69:9)
at exports.runSuite (E:\dev\projects\moo\test\dep\node_modules
\nodeunit\lib\core.js:117:25)
at _concat (E:\dev\projects\moo\test\dep\node_modules\nodeunit\deps
\async.js:508:13)
at async.forEachSeries.iterate (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\deps\async.js:118:13)
at async.forEachSeries.iterate (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\deps\async.js:129:25)
at _concat (E:\dev\projects\moo\test\dep\node_modules\nodeunit\deps
\async.js:510:17)
at exports.test.test.done (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\lib\types.js:146:17)
Caused by : Error: CRASH!
at Object.module.exports.doSomethingElse (E:\dev\projects\moo
\server\test\errors-test.js:60:55)
at Object.wrapTest (E:\dev\projects\moo\test\dep\node_modules
\nodeunit\lib\core.js:235:16)
at wrapTest (E:\dev\projects\moo\test\dep\node_modules\nodeunit\lib
\core.js:235:16)
at Object.exports.runTest (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\lib\core.js:69:9)
at exports.runSuite (E:\dev\projects\moo\test\dep\node_modules
\nodeunit\lib\core.js:117:25)
at _concat (E:\dev\projects\moo\test\dep\node_modules\nodeunit\deps
\async.js:508:13)
at async.forEachSeries.iterate (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\deps\async.js:118:13)
at async.forEachSeries.iterate (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\deps\async.js:129:25)
at _concat (E:\dev\projects\moo\test\dep\node_modules\nodeunit\deps
\async.js:510:17)
at exports.test.test.done (E:\dev\projects\moo\test\dep
\node_modules\nodeunit\lib\types.js:146:17)
(In this case there is a lot of repetition - but in reality its rarely
the case because the error and nested error are on completely
different call stacks)
When Q tries to format the error stacktrace, we get
NestedError: BANG!
N
e
s
t
e
d
E
r
r
o
r
:
B
A
N
G
!
a
t
m
o
o
(
E
:
\
d
e
v
\
p
r
o
j
e
c
t
s
\
m
o
o
\
<snip - its too long :) >
Wondering if we should change our NestedError impl so Q doesnt make
the stack trace unreadable.
Or whether we should consider changing Q.
Cheers,
M