Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
E.Azer Koçulu
committed
Mar 14, 2014
1 parent
f35b9d1
commit 6211d2a
Showing
4 changed files
with
67 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var failingLine = require('./'); | ||
|
||
process.on('uncaughtException', function (error) { | ||
console.log(failingLine(error)); | ||
}); | ||
|
||
if (true) { | ||
hereIfail++; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
var find = require("findall"); | ||
|
||
module.exports = failingLine; | ||
|
||
function failingLine (error, shift) { | ||
var match = find(error.stack, /\(([^\(\)]+)\)/g); | ||
if (!match) return undefined; | ||
if (!error || !error.stack) return; | ||
|
||
var index = 1; | ||
if (shift) index += shift; | ||
|
||
var fn, filename, line, col; | ||
var stack = error.stack.split('\n')[index]; | ||
var match = stack.match(/at ([\w\.<>\[\]\s]+) \(([^:]+):(\d+):(\d+)/); | ||
|
||
if (!match) { | ||
match = stack.match(/at ([^:]+):(\d+):(\d+)/); | ||
if (!match) return undefined; | ||
|
||
match = match[0 + (shift || 0)].split(':'); | ||
filename = match[1]; | ||
line = Number(match[2]); | ||
col = Number(match[3]); | ||
} else { | ||
fn = match[1]; | ||
filename = match[2]; | ||
line = Number(match[3]); | ||
col = Number(match[4]); | ||
} | ||
|
||
return { | ||
filename: match[0], | ||
lineno: Number(match[1]) | ||
fn: fn, | ||
filename: filename, | ||
line: line, | ||
col: col | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,8 +20,5 @@ | |
"type": "git" | ||
}, | ||
"author": "azer", | ||
"license": "BSD", | ||
"dependencies": { | ||
"findall": "0.0.4" | ||
} | ||
"license": "BSD" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters