Skip to content

Commit

Permalink
Capture stack trace in node.js
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-homyakov committed Nov 15, 2013
1 parent 8c4edbb commit b9edc2d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 1 addition & 2 deletions test/functional/ExceptionLab.html
Expand Up @@ -27,14 +27,13 @@
}

function dumpException(ex) {
ex = ex || new Error("Default error");
var text = "{\n " + ExceptionLab.getExceptionProps(ex).join(",\n ") + "\n}";
info(text);
lastException = ex;
}

function dumpExceptionError() {
dumpException();
dumpException(new Error("Default error"));
}

function dumpExceptionAnonymous() {
Expand Down
3 changes: 2 additions & 1 deletion test/functional/ExceptionLab.js
Expand Up @@ -25,7 +25,8 @@
name: true,
stack: true,
stacktrace: true,
'arguments': true
'arguments': true,
type: true
};

// find all (including non-enumerable) own properties
Expand Down
20 changes: 13 additions & 7 deletions test/functional/testNode.js
@@ -1,19 +1,26 @@
/*global require, console*/
var ExceptionLab = require("./ExceptionLab");
//stacktrace.js
var printStackTrace = require("../../stacktrace");

var lastException;

function info(text) {
console.log(text);
}

function dumpStacktrace(guess) {
var trace = printStackTrace({
e: lastException,
guess: guess
});
info(trace.join("\n"));
}

function dumpException(ex) {
ex = ex || new Error("Default error");
var text = "{\n " + ExceptionLab.getExceptionProps(ex).join(",\n ") + "\n}";
info(text);
//info(ex.arguments);
lastException = ex;
console.log(ex.arguments);
}

function dumpExceptionMultiLine() {
Expand All @@ -29,9 +36,8 @@ function dumpExceptionMultiLine() {
}
}

info("Exception properties:");
dumpExceptionMultiLine();

/*
> Object.getOwnPropertyNames(lastException)
[ 'stack', 'arguments', 'type', 'message' ]
*/
info("\nException stack trace:");
dumpStacktrace();

0 comments on commit b9edc2d

Please sign in to comment.