Skip to content

Commit ec0f30b

Browse files
author
Eric Wendelin
committed
Fix parsing locations with port numbers.
1 parent 457ee71 commit ec0f30b

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

bower.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "error-stack-parser",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "./error-stack-parser.js",
5-
"homepage": "https://github.com/stacktracejs/error-stack-parser.js",
5+
"homepage": "https://github.com/stacktracejs/error-stack-parser",
66
"authors": [
77
"Eric Wendelin <me@eriwen.com>"
88
],
99
"description": "Extract meaning from JS Errors",
1010
"dependencies": {
11-
"stackframe": "0.1.0"
11+
"stackframe": "~0.1.0"
1212
},
1313
"devDependencies": {
1414
"jasmine": "~1.3.1",
@@ -27,7 +27,7 @@
2727
"framework-agnostic",
2828
"error"
2929
],
30-
"license": "MIT",
30+
"license": "Public Domain",
3131
"ignore": [
3232
"**/.*",
3333
"node_modules",

component.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "error-stack-parser",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "./error-stack-parser.js",
55
"dependencies": {
66
"stackframe": "0.1.0"

error-stack-parser.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,41 @@
3232
}
3333
};
3434

35+
/**
36+
* Separate line and column numbers from a URL-like string.
37+
* @param urlLike String
38+
* @return Array[String]
39+
*/
40+
this.extractLocation = function extractLocation(urlLike) {
41+
var locationParts = urlLike.split(':');
42+
var lastNumber = locationParts.pop();
43+
var possibleNumber = locationParts[locationParts.length - 1];
44+
if (possibleNumber != Number(possibleNumber)) {
45+
return [locationParts.join(':'), lastNumber, undefined];
46+
} else {
47+
var lineNumber = locationParts.pop();
48+
return [locationParts.join(':'), lineNumber, lastNumber];
49+
}
50+
};
51+
3552
this.parseV8OrIE = function parseV8OrIE(error) {
3653
return error.stack.split('\n').splice(1).map(function (line) {
3754
var tokens = line.split(/\s+/).splice(2);
38-
var location = tokens.pop().replace(/[\(\)\s]/g, '').split(':');
55+
var locationParts = this.extractLocation(tokens.pop().replace(/[\(\)\s]/g, ''));
3956
var functionName = (!tokens[0] || tokens[0] === 'Anonymous') ? undefined : tokens[0];
40-
return new StackFrame(functionName, undefined, location[0] + ':' + location[1], location[2], location[3]);
41-
});
57+
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]);
58+
}.bind(this));
4259
};
4360

4461
this.parseFFOrSafari = function parseFFOrSafari(error) {
4562
return error.stack.split('\n').filter(function (line) {
4663
return !!line.match(this.firefoxSafariStackEntryRegExp);
4764
}.bind(this)).map(function (line) {
4865
var tokens = line.split('@');
49-
var location = tokens.pop().split(':');
66+
var locationParts = this.extractLocation(tokens.pop());
5067
var functionName = tokens.shift() || undefined;
51-
return new StackFrame(functionName, undefined, location[0] + ':' + location[1], location[2], location[3]);
52-
});
68+
return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2]);
69+
}.bind(this));
5370
};
5471

5572
this.parseOpera = function parseOpera(e) {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"name": "error-stack-parser",
33
"description": "Extract meaning from JS Errors",
44
"author": "Eric Wendelin <me@eriwen.com> (http://eriwen.com)",
5-
"version": "0.1.0",
5+
"version": "0.1.1",
66
"keywords": ["stacktrace", "error"],
77
"homepage": "http://www.stacktracejs.com",
88
"dependencies": {
9-
"stackframe": "0.1.0"
9+
"stackframe": "~0.1.0"
1010
},
1111
"repository": {
1212
"type": "git",

spec/captured-errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ CapturedExceptions.CHROME_36 = {
159159
message: "Default error",
160160
name: "Error",
161161
stack: "Error: Default error\n" +
162-
" at dumpExceptionError (file:///Users/eric/src/stacktracejs/stacktrace.js/test/functional/ExceptionLab.html:41:27)\n" +
163-
" at HTMLButtonElement.onclick (file:///Users/eric/src/stacktracejs/stacktrace.js/test/functional/ExceptionLab.html:107:146)"
162+
" at dumpExceptionError (http://localhost:8080/file.js:41:27)\n" +
163+
" at HTMLButtonElement.onclick (http://localhost:8080/file.js:107:146)"
164164
};
165165

166166
CapturedExceptions.FIREFOX_3 = {

spec/error-stack-parser-spec.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('ErrorStackParser', function () {
2828
expect(stackFrames[1]).toMatchStackFrame(['bar', undefined, 'http://path/to/file.js', 1, 1]);
2929
});
3030

31-
it('should parse V8 Error stacks', function () {
31+
it('should parse V8 Error.stack', function () {
3232
var stackFrames = unit.parse(CapturedExceptions.CHROME_15);
3333
expect(stackFrames).toBeTruthy();
3434
expect(stackFrames.length).toBe(4);
@@ -38,6 +38,13 @@ describe('ErrorStackParser', function () {
3838
expect(stackFrames[3]).toMatchStackFrame([undefined, undefined, 'http://path/to/file.js', 24, 4]);
3939
});
4040

41+
it('should parse V8 Error.stack entries with port numbers', function () {
42+
var stackFrames = unit.parse(CapturedExceptions.CHROME_36);
43+
expect(stackFrames).toBeTruthy();
44+
expect(stackFrames.length).toBe(2);
45+
expect(stackFrames[0]).toMatchStackFrame(['dumpExceptionError', undefined, 'http://localhost:8080/file.js', 41, 27]);
46+
});
47+
4148
it('should parse IE 10 Error stacks', function () {
4249
var stackFrames = unit.parse(CapturedExceptions.IE_10);
4350
expect(stackFrames).toBeTruthy();

0 commit comments

Comments
 (0)