Skip to content

Commit

Permalink
Ignore level in logDebug. Workaround for getsentry#373, avoids crashi…
Browse files Browse the repository at this point in the history
…ng raven-js when both the console plugin is loaded and Raven.debug===true.
  • Loading branch information
benoitg committed Aug 25, 2015
1 parent fb26b90 commit 60b7bc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,12 @@ function logDebug(level) {
if (originalConsole[level] && Raven.debug) {
// _slice is coming from vendor/TraceKit/tracekit.js
// so it's accessible globally
originalConsole[level].apply(originalConsole, _slice.call(arguments, 1));
//The console plugin cause infinite recursion if logDebug is called
//See https://github.com/getsentry/raven-js/issues/373
//originalConsole[level].apply(originalConsole, _slice.call(arguments, 1));
//As a temporary workaround, we ignore the level and call 'log', which
//is ignored by the console plugin
originalConsole.log.apply(originalConsole, _slice.call(arguments, 1));
}
}

Expand Down
10 changes: 8 additions & 2 deletions test/raven.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,21 @@ describe('globals', function() {
it('should not write to console when Raven.debug is false', function() {
Raven.debug = false;
this.sinon.stub(originalConsole, level);
this.sinon.stub(originalConsole, 'log');
logDebug(level, message);
assert.isFalse(originalConsole[level].called);
//Temporary fix, see https://github.com/getsentry/raven-js/issues/373
//assert.isFalse(originalConsole[level].called);
assert.isFalse(originalConsole.log.called);
});

it('should write to console when Raven.debug is true', function() {
Raven.debug = true;
this.sinon.stub(originalConsole, level);
this.sinon.stub(originalConsole, 'log');
logDebug(level, message);
assert.isTrue(originalConsole[level].calledOnce);
//Temporary fix, see https://github.com/getsentry/raven-js/issues/373
//assert.isTrue(originalConsole[level].calledOnce);
assert.isTrue(originalConsole.log.calledOnce);
});

it('should handle variadic arguments', function() {
Expand Down

0 comments on commit 60b7bc2

Please sign in to comment.