Skip to content

Commit 1006ff3

Browse files
committed
Move into angular plugin
1 parent 5bac419 commit 1006ff3

File tree

3 files changed

+24
-38
lines changed

3 files changed

+24
-38
lines changed

plugins/angular.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,39 @@ function ExceptionHandlerProvider($provide) {
2424
}
2525

2626
function exceptionHandler(Raven, $delegate) {
27-
return function (ex, cause) {
27+
return function (ex, cause) {
2828
Raven.captureException(ex, {
2929
extra: { cause: cause }
3030
});
3131
$delegate(ex, cause);
3232
};
3333
}
3434

35+
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
36+
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
37+
3538
Raven.addPlugin(function () {
3639
angular.module('ngRaven', [])
3740
.provider('Raven', RavenProvider)
3841
.config(['$provide', ExceptionHandlerProvider]);
3942
});
4043

44+
Raven.setDataCallback(function(data) {
45+
// We only care about mutating an exception
46+
var exception = data.exception;
47+
if (exception) {
48+
exception = exception.values[0];
49+
var matches = angularPattern.exec(exception.value);
50+
51+
if (matches) {
52+
// This type now becomes something like: $rootScope:inprog
53+
exception.type = matches[1];
54+
exception.value = matches[2];
55+
data.message = exception.type + ': ' + exception.value;
56+
// auto set a new tag specifically for the angular error url
57+
data.extra.angularDocs = matches[3];
58+
}
59+
}
60+
});
61+
4162
}(typeof window !== 'undefined' ? window : this));

src/raven.js

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

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

487486
function RavenConfigError(message) {
488487
this.name = 'RavenConfigError';
@@ -569,19 +568,7 @@ function each(obj, callback) {
569568
}
570569

571570
function handleStackInfo(stackInfo, options) {
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-
}
571+
var frames = [];
585572

586573
if (stackInfo.stack && stackInfo.stack.length) {
587574
each(stackInfo.stack, function(i, stack) {

test/raven.test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,28 +1553,6 @@ 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-
});
15781556
});
15791557

15801558
describe('joinRegExp', function() {

0 commit comments

Comments
 (0)