Skip to content
Browse files

Now returns a stack trace when possible. Doesn't just say [object Obj…

…ect] in node.js console for uncaught exceptions
  • Loading branch information...
1 parent 135b6b9 commit 57507fb6a1b7f1f27f7f1a771a8b943d81d52ebf Wa committed
Showing with 15 additions and 2 deletions.
  1. +15 −2 exception.js
View
17 exception.js
@@ -29,11 +29,24 @@ function paramNames(func){
}
function exception(th){
- var fn = arguments.callee.caller, pn = paramNames(fn), a = fn.arguments;
+ var fn = arguments.callee.caller, pn = paramNames(fn), a = fn.arguments, stackMsg = "";
if(!(0 in arguments))th = {};
- th.name = fn.name;
+ th.type = th.name = fn.name;
for(var i=0;i<pn.length;++i){
th[pn[i]] = a[i];
+ stackMsg += pn[i]+": "+(
+ (typeof(a[i])=="string")?'"'+a[i]+'"':a[i]
+ )+" ";
+ }
+ if(typeof(Error) != "undefined"){
+ var stack = (new Error("<message>")).stack;
+ if("toString" in th && th.toString() != "[object Object]"){
+ stackMsg = th.toString();
+ }
+ stack = stack.split("\n");
+ stack[0] = stack[0].replace("Error",th.name).replace("<message>",stackMsg);
+ stack.splice(1,1); //Remove place in "exception"
+ th.stack = stack.join("\n");
}
return th;
}

0 comments on commit 57507fb

Please sign in to comment.
Something went wrong with that request. Please try again.