Skip to content

Commit b311690

Browse files
committed
Remove remaining deprecated context/fetchContext code
1 parent 6bed42f commit b311690

File tree

4 files changed

+101
-258
lines changed

4 files changed

+101
-258
lines changed

src/raven.js

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,13 +1042,7 @@ Raven.prototype = {
10421042
lineno: frame.line,
10431043
colno: frame.column,
10441044
'function': frame.func || '?'
1045-
}, context = this._extractContextFromFrame(frame), i;
1046-
1047-
if (context) {
1048-
var keys = ['pre_context', 'context_line', 'post_context'];
1049-
i = 3;
1050-
while (i--) normalized[keys[i]] = context[i];
1051-
}
1045+
};
10521046

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

1065-
_extractContextFromFrame: function(frame) {
1066-
// immediately check if we should even attempt to parse a context
1067-
if (!frame.context || !this._globalOptions.fetchContext) return;
1068-
1069-
var context = frame.context,
1070-
pivot = ~~(context.length / 2),
1071-
i = context.length, isMinified = false;
1072-
1073-
while (i--) {
1074-
// We're making a guess to see if the source is minified or not.
1075-
// To do that, we make the assumption if *any* of the lines passed
1076-
// in are greater than 300 characters long, we bail.
1077-
// Sentry will see that there isn't a context
1078-
if (context[i].length > 300) {
1079-
isMinified = true;
1080-
break;
1081-
}
1082-
}
1083-
1084-
if (isMinified) {
1085-
// The source is minified and we don't know which column. Fuck it.
1086-
if (isUndefined(frame.column)) return;
1087-
1088-
// If the source is minified and has a frame column
1089-
// we take a chunk of the offending line to hopefully shed some light
1090-
return [
1091-
[], // no pre_context
1092-
context[pivot].substr(frame.column, 50), // grab 50 characters, starting at the offending column
1093-
[] // no post_context
1094-
];
1095-
}
1096-
1097-
return [
1098-
context.slice(0, pivot), // pre_context
1099-
context[pivot], // context_line
1100-
context.slice(pivot + 1) // post_context
1101-
];
1102-
},
1103-
11041059
_processException: function(type, message, fileurl, lineno, frames, options) {
11051060
var stacktrace, fullMessage;
11061061

test/raven.test.js

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@ describe('globals', function() {
246246

247247
describe('normalizeFrame', function() {
248248
it('should handle a normal frame', function() {
249-
var context = [
250-
['line1'], // pre
251-
'line2', // culprit
252-
['line3'] // post
253-
];
254-
this.sinon.stub(Raven, '_extractContextFromFrame').returns(context);
255249
var frame = {
256250
url: 'http://example.com/path/file.js',
257251
line: 10,
@@ -267,25 +261,18 @@ describe('globals', function() {
267261
lineno: 10,
268262
colno: 11,
269263
'function': 'lol',
270-
pre_context: ['line1'],
271-
context_line: 'line2',
272-
post_context: ['line3'],
273264
in_app: true
274265
});
275266
});
276267

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

287-
Raven._globalOptions.fetchContext = true;
288-
289276
assert.deepEqual(Raven._normalizeFrame(frame), {
290277
filename: 'http://example.com/path/file.js',
291278
lineno: 10,
@@ -296,13 +283,11 @@ describe('globals', function() {
296283
});
297284

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

308293
Raven._globalOptions.fetchContext = true;
@@ -318,13 +303,11 @@ describe('globals', function() {
318303
});
319304

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

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

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

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

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

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

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

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

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

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

418393
it('should not blow up if includePaths is empty, regression for #377', function() {
419-
this.sinon.stub(Raven, '_extractContextFromFrame').returns(undefined);
420394
var frame = {
421395
url: 'http://lol.com/path/file.js',
422396
line: 10,
423397
column: 11,
424398
func: 'TraceKit.lol'
425-
// context: [] context is stubbed
426399
};
427400
Raven._globalOptions.includePaths = [];
428401
Raven._normalizeFrame(frame);
429402
});
430403
});
431404

432-
describe('extractContextFromFrame', function() {
433-
it('should handle a normal frame', function() {
434-
var frame = {
435-
column: 2,
436-
context: [
437-
'line1',
438-
'line2',
439-
'line3',
440-
'line4',
441-
'line5',
442-
'culprit',
443-
'line7',
444-
'line8',
445-
'line9',
446-
'line10',
447-
'line11'
448-
]
449-
};
450-
var context = Raven._extractContextFromFrame(frame);
451-
assert.deepEqual(context, [
452-
['line1', 'line2', 'line3', 'line4', 'line5'],
453-
'culprit',
454-
['line7', 'line8', 'line9', 'line10', 'line11']
455-
]);
456-
});
457-
458-
it('should return nothing if there is no context', function() {
459-
var frame = {
460-
column: 2
461-
};
462-
assert.isUndefined(Raven._extractContextFromFrame(frame));
463-
});
464-
465-
it('should reject a context if a line is too long without a column', function() {
466-
var frame = {
467-
context: [
468-
new Array(1000).join('f') // generate a line that is 1000 chars long
469-
]
470-
};
471-
assert.isUndefined(Raven._extractContextFromFrame(frame));
472-
});
473-
474-
it('should reject a minified context with fetchContext disabled', function() {
475-
var frame = {
476-
column: 2,
477-
context: [
478-
'line1',
479-
'line2',
480-
'line3',
481-
'line4',
482-
'line5',
483-
'culprit',
484-
'line7',
485-
'line8',
486-
'line9',
487-
'line10',
488-
'line11'
489-
]
490-
};
491-
Raven._globalOptions.fetchContext = false;
492-
assert.isUndefined(Raven._extractContextFromFrame(frame));
493-
});
494-
495-
it('should truncate the minified line if there is a column number without sourcemaps enabled', function() {
496-
// Note to future self:
497-
// Array(51).join('f').length === 50
498-
var frame = {
499-
column: 2,
500-
context: [
501-
'aa' + (new Array(51).join('f')) + (new Array(500).join('z'))
502-
]
503-
};
504-
assert.deepEqual(Raven._extractContextFromFrame(frame), [[], new Array(51).join('f'), []]);
505-
});
506-
});
507-
508405
describe('processException', function() {
509406
it('should respect `ignoreErrors`', function() {
510407
this.sinon.stub(Raven, '_send');

0 commit comments

Comments
 (0)