Skip to content

Commit b9edc2d

Browse files
Capture stack trace in node.js
1 parent 8c4edbb commit b9edc2d

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

test/functional/ExceptionLab.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
}
2828

2929
function dumpException(ex) {
30-
ex = ex || new Error("Default error");
3130
var text = "{\n " + ExceptionLab.getExceptionProps(ex).join(",\n ") + "\n}";
3231
info(text);
3332
lastException = ex;
3433
}
3534

3635
function dumpExceptionError() {
37-
dumpException();
36+
dumpException(new Error("Default error"));
3837
}
3938

4039
function dumpExceptionAnonymous() {

test/functional/ExceptionLab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
name: true,
2626
stack: true,
2727
stacktrace: true,
28-
'arguments': true
28+
'arguments': true,
29+
type: true
2930
};
3031

3132
// find all (including non-enumerable) own properties

test/functional/testNode.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
/*global require, console*/
22
var ExceptionLab = require("./ExceptionLab");
3-
//stacktrace.js
3+
var printStackTrace = require("../../stacktrace");
44

55
var lastException;
66

77
function info(text) {
88
console.log(text);
99
}
1010

11+
function dumpStacktrace(guess) {
12+
var trace = printStackTrace({
13+
e: lastException,
14+
guess: guess
15+
});
16+
info(trace.join("\n"));
17+
}
18+
1119
function dumpException(ex) {
12-
ex = ex || new Error("Default error");
1320
var text = "{\n " + ExceptionLab.getExceptionProps(ex).join(",\n ") + "\n}";
1421
info(text);
22+
//info(ex.arguments);
1523
lastException = ex;
16-
console.log(ex.arguments);
1724
}
1825

1926
function dumpExceptionMultiLine() {
@@ -29,9 +36,8 @@ function dumpExceptionMultiLine() {
2936
}
3037
}
3138

39+
info("Exception properties:");
3240
dumpExceptionMultiLine();
3341

34-
/*
35-
> Object.getOwnPropertyNames(lastException)
36-
[ 'stack', 'arguments', 'type', 'message' ]
37-
*/
42+
info("\nException stack trace:");
43+
dumpStacktrace();

0 commit comments

Comments
 (0)