Skip to content

Commit

Permalink
captureStackTrace if error object is passed but err.stack is undefine…
Browse files Browse the repository at this point in the history
…d, this happens f.e. in case of RangeError
  • Loading branch information
kof committed May 23, 2012
1 parent 87732f0 commit 6cca37b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"author": "Chris Dickinson <chris@neversaw.us> (http://neversaw.us/)", "author": "Chris Dickinson <chris@neversaw.us> (http://neversaw.us/)",
"name": "tracejs", "name": "tracejs",
"description": "Expand Error.stack traces into usable objects providing context and highlighting", "description": "Expand Error.stack traces into usable objects providing context and highlighting",
"version": "0.1.4", "version": "0.1.5",
"homepage": "http://github.com/chrisdickinson/tracejs/", "homepage": "http://github.com/chrisdickinson/tracejs/",
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down
11 changes: 6 additions & 5 deletions trace.js
Expand Up @@ -152,7 +152,7 @@ Frame.prototype.toString = function() {
}; };


Frame.prototype.get_lines = function(context, ascii_cursor, highlight_error_start) { Frame.prototype.get_lines = function(context, ascii_cursor, highlight_error_start) {
context = context || 0; context = context || 0;
filedata = this.filedata().split('\n'); filedata = this.filedata().split('\n');


var start_line = this.line - context - 1, var start_line = this.line - context - 1,
Expand Down Expand Up @@ -194,10 +194,11 @@ Frame.prototype.get_lines = function(context, ascii_cursor, highlight_error_star
return lines.join('\n'); return lines.join('\n');
}; };


var trace = function(err) { var trace = function trace(err) {
if(!err) { err || (err = {});
err = {};
Error.captureStackTrace(err); if (!err.stack) {
Error.captureStackTrace(err, trace);
} }


var lines = err.stack.split('\n'), var lines = err.stack.split('\n'),
Expand Down

0 comments on commit 6cca37b

Please sign in to comment.