Skip to content

Commit 5bac419

Browse files
committed
Handle a native angular minErr by deconstructing it
Fixes GH-243 See: https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
1 parent 26b0db8 commit 5bac419

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/raven.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ function triggerEvent(eventType, options) {
481481
}
482482

483483
var dsnKeys = 'source protocol user pass host port path'.split(' '),
484-
dsnPattern = /^(?:(\w+):)?\/\/(?:(\w+)(:\w+)?@)?([\w\.-]+)(?::(\d+))?(\/.*)/;
484+
dsnPattern = /^(?:(\w+):)?\/\/(?:(\w+)(:\w+)?@)?([\w\.-]+)(?::(\d+))?(\/.*)/,
485+
angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
485486

486487
function RavenConfigError(message) {
487488
this.name = 'RavenConfigError';
@@ -568,7 +569,19 @@ function each(obj, callback) {
568569
}
569570

570571
function handleStackInfo(stackInfo, options) {
571-
var frames = [];
572+
var frames = [],
573+
matches = angularPattern.exec(stackInfo.message);
574+
575+
if (matches) {
576+
stackInfo.name = matches[1];
577+
stackInfo.message = matches[2];
578+
// auto set a new tag specifically for the angular error url
579+
options = options || {};
580+
options.extra = objectMerge({
581+
// Truncate this message pretty short since it can be insane.
582+
ref: truncate(matches[3], 250)
583+
}, options.extra);
584+
}
572585

573586
if (stackInfo.stack && stackInfo.stack.length) {
574587
each(stackInfo.stack, function(i, stack) {

test/raven.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,6 +1553,28 @@ describe('globals', function() {
15531553
'new <anonymous>', 'hey', 'http://example.com', 10, [], undefined
15541554
]);
15551555
});
1556+
1557+
it('should extract angularjs specific error messages', function() {
1558+
this.sinon.stub(window, 'normalizeFrame').returns(undefined);
1559+
this.sinon.stub(window, 'processException');
1560+
1561+
var stackInfo = {
1562+
name: 'Error',
1563+
message: '[$foo:bar] thing happened\nhttp://errors.angularjs.org/cool/story',
1564+
url: 'http://example.com',
1565+
lineno: 10
1566+
};
1567+
1568+
handleStackInfo(stackInfo);
1569+
assert.deepEqual(window.processException.lastCall.args, [
1570+
'$foo:bar',
1571+
'thing happened',
1572+
'http://example.com',
1573+
10,
1574+
[],
1575+
{extra: {ref: 'http://errors.angularjs.org/cool/story'}}
1576+
]);
1577+
});
15561578
});
15571579

15581580
describe('joinRegExp', function() {

0 commit comments

Comments
 (0)