Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 1 addition & 46 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,13 +1042,7 @@ Raven.prototype = {
lineno: frame.line,
colno: frame.column,
'function': frame.func || '?'
}, context = this._extractContextFromFrame(frame), i;

if (context) {
var keys = ['pre_context', 'context_line', 'post_context'];
i = 3;
while (i--) normalized[keys[i]] = context[i];
}
};

normalized.in_app = !( // determine if an exception came from outside of our app
// first we check the global includePaths list.
Expand All @@ -1062,45 +1056,6 @@ Raven.prototype = {
return normalized;
},

_extractContextFromFrame: function(frame) {
// immediately check if we should even attempt to parse a context
if (!frame.context || !this._globalOptions.fetchContext) return;

var context = frame.context,
pivot = ~~(context.length / 2),
i = context.length, isMinified = false;

while (i--) {
// We're making a guess to see if the source is minified or not.
// To do that, we make the assumption if *any* of the lines passed
// in are greater than 300 characters long, we bail.
// Sentry will see that there isn't a context
if (context[i].length > 300) {
isMinified = true;
break;
}
}

if (isMinified) {
// The source is minified and we don't know which column. Fuck it.
if (isUndefined(frame.column)) return;

// If the source is minified and has a frame column
// we take a chunk of the offending line to hopefully shed some light
return [
[], // no pre_context
context[pivot].substr(frame.column, 50), // grab 50 characters, starting at the offending column
[] // no post_context
];
}

return [
context.slice(0, pivot), // pre_context
context[pivot], // context_line
context.slice(pivot + 1) // post_context
];
},

_processException: function(type, message, fileurl, lineno, frames, options) {
var stacktrace, fullMessage;

Expand Down
103 changes: 0 additions & 103 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ describe('globals', function() {

describe('normalizeFrame', function() {
it('should handle a normal frame', function() {
var context = [
['line1'], // pre
'line2', // culprit
['line3'] // post
];
this.sinon.stub(Raven, '_extractContextFromFrame').returns(context);
var frame = {
url: 'http://example.com/path/file.js',
line: 10,
Expand All @@ -267,25 +261,18 @@ describe('globals', function() {
lineno: 10,
colno: 11,
'function': 'lol',
pre_context: ['line1'],
context_line: 'line2',
post_context: ['line3'],
in_app: true
});
});

it('should handle a frame without context', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://example.com/path/file.js',
line: 10,
column: 11,
func: 'lol'
// context: [] context is stubbed
};

Raven._globalOptions.fetchContext = true;

assert.deepEqual(Raven._normalizeFrame(frame), {
filename: 'http://example.com/path/file.js',
lineno: 10,
Expand All @@ -296,13 +283,11 @@ describe('globals', function() {
});

it('should not mark `in_app` if rules match', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://example.com/path/file.js',
line: 10,
column: 11,
func: 'lol'
// context: [] context is stubbed
};

Raven._globalOptions.fetchContext = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed.

Expand All @@ -318,13 +303,11 @@ describe('globals', function() {
});

it('should mark `in_app` if rules do not match', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/file.js',
line: 10,
column: 11,
func: 'lol'
// context: [] context is stubbed
};

Raven._globalOptions.fetchContext = true;
Expand All @@ -340,13 +323,11 @@ describe('globals', function() {
});

it('should mark `in_app` for raven.js', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/raven.js',
line: 10,
column: 11,
func: 'lol'
// context: [] context is stubbed
};

assert.deepEqual(Raven._normalizeFrame(frame), {
Expand All @@ -359,13 +340,11 @@ describe('globals', function() {
});

it('should mark `in_app` for raven.min.js', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/raven.min.js',
line: 10,
column: 11,
func: 'lol'
// context: [] context is stubbed
};

assert.deepEqual(Raven._normalizeFrame(frame), {
Expand All @@ -378,13 +357,11 @@ describe('globals', function() {
});

it('should mark `in_app` for Raven', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/file.js',
line: 10,
column: 11,
func: 'Raven.wrap'
// context: [] context is stubbed
};

assert.deepEqual(Raven._normalizeFrame(frame), {
Expand All @@ -397,13 +374,11 @@ describe('globals', function() {
});

it('should mark `in_app` for TraceKit', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/file.js',
line: 10,
column: 11,
func: 'TraceKit.lol'
// context: [] context is stubbed
};

assert.deepEqual(Raven._normalizeFrame(frame), {
Expand All @@ -416,95 +391,17 @@ describe('globals', function() {
});

it('should not blow up if includePaths is empty, regression for #377', function() {
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
var frame = {
url: 'http://lol.com/path/file.js',
line: 10,
column: 11,
func: 'TraceKit.lol'
// context: [] context is stubbed
};
Raven._globalOptions.includePaths = [];
Raven._normalizeFrame(frame);
});
});

describe('extractContextFromFrame', function() {
it('should handle a normal frame', function() {
var frame = {
column: 2,
context: [
'line1',
'line2',
'line3',
'line4',
'line5',
'culprit',
'line7',
'line8',
'line9',
'line10',
'line11'
]
};
var context = Raven._extractContextFromFrame(frame);
assert.deepEqual(context, [
['line1', 'line2', 'line3', 'line4', 'line5'],
'culprit',
['line7', 'line8', 'line9', 'line10', 'line11']
]);
});

it('should return nothing if there is no context', function() {
var frame = {
column: 2
};
assert.isUndefined(Raven._extractContextFromFrame(frame));
});

it('should reject a context if a line is too long without a column', function() {
var frame = {
context: [
new Array(1000).join('f') // generate a line that is 1000 chars long
]
};
assert.isUndefined(Raven._extractContextFromFrame(frame));
});

it('should reject a minified context with fetchContext disabled', function() {
var frame = {
column: 2,
context: [
'line1',
'line2',
'line3',
'line4',
'line5',
'culprit',
'line7',
'line8',
'line9',
'line10',
'line11'
]
};
Raven._globalOptions.fetchContext = false;
assert.isUndefined(Raven._extractContextFromFrame(frame));
});

it('should truncate the minified line if there is a column number without sourcemaps enabled', function() {
// Note to future self:
// Array(51).join('f').length === 50
var frame = {
column: 2,
context: [
'aa' + (new Array(51).join('f')) + (new Array(500).join('z'))
]
};
assert.deepEqual(Raven._extractContextFromFrame(frame), [[], new Array(51).join('f'), []]);
});
});

describe('processException', function() {
it('should respect `ignoreErrors`', function() {
this.sinon.stub(Raven, '_send');
Expand Down
Loading