Permalink
Browse files

Adjusted the stack parser to pass tests

  • Loading branch information...
1 parent bb67878 commit 5507d9a46f3fa2145761611d2d85c2619eb3994b @mattrobenolt mattrobenolt committed Mar 18, 2012
Showing with 12 additions and 6 deletions.
  1. +12 −6 lib/utils.js
View
@@ -105,12 +105,16 @@ module.exports.parseStack = function parseStack(stack, callback) {
var lines = stack.split('\n').slice(1), callbacks=lines.length, frames=[], cache={};
lines.forEach(function(line, index) {
- var data = line.match(/^\s*at (.+?) \((.+?):(\d+):(\d+)\)$/).slice(1),
+ var data = line.match(/^\s*at (?:(.+?) )?\(?(.+?)(?::(\d+):(\d+))?\)?$/).slice(1),
frame = {
- 'function': data[0],
filename: data[1],
lineno: ~~data[2]
};
+
+ // only set the function key if it exists
+ if(data[0]) {
+ frame['function'] = data[0];
+ }
// internal Node files are not full path names. Ignore them.
if(frame.filename[0] === '/' || frame.filename[0] === '.') {
// check if it has been read in first
@@ -119,9 +123,12 @@ module.exports.parseStack = function parseStack(stack, callback) {
if(--callbacks === 0) callback(null, frames);
} else {
fs.readFile(frame.filename, function(err, file) {
- file = file.toString().split('\n');
- cache[frame.filename] = file;
- parseLines(file);
+ if(!err) {
+ file = file.toString().split('\n');
+ cache[frame.filename] = file;
+ parseLines(file);
+ }
+ frames[index] = frame;
if(--callbacks === 0) callback(null, frames);
});
}
@@ -134,7 +141,6 @@ module.exports.parseStack = function parseStack(stack, callback) {
frame.pre_context = lines.slice(Math.max(0, frame.lineno-(LINES_OF_CONTEXT+1)), frame.lineno-1);
frame.context_line = lines[frame.lineno-1];
frame.post_context = lines.slice(frame.lineno, frame.lineno+LINES_OF_CONTEXT);
- frames[index] = frame;
}
});
};

0 comments on commit 5507d9a

Please sign in to comment.