Skip to content

Commit aa72795

Browse files
authored
fix: Attempt to provide some information for <unlabeled event> (#1397)
1 parent deff2f0 commit aa72795

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/raven-js/src/raven.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ Raven.prototype = {
616616
return;
617617
}
618618

619-
if (this._globalOptions.stacktrace || (options && options.stacktrace)) {
619+
// Always attempt to get stacktrace if message is empty.
620+
// It's the only way to provide any helpful information to the user.
621+
if (this._globalOptions.stacktrace || options.stacktrace || data.message === '') {
620622
// fingerprint on msg, not stack trace (legacy behavior, could be revisited)
621623
data.fingerprint = data.fingerprint == null ? msg : data.fingerprint;
622624

@@ -1773,6 +1775,11 @@ Raven.prototype = {
17731775
options
17741776
);
17751777

1778+
var ex = data.exception.values[0];
1779+
if (ex.type == null && ex.value === '') {
1780+
ex.value = 'Unrecoverable error caught';
1781+
}
1782+
17761783
// Move mechanism from options to exception interface
17771784
// We do this, as requiring user to pass `{exception:{mechanism:{ ... }}}` would be
17781785
// too much

packages/raven-js/test/raven.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,20 @@ describe('globals', function() {
807807
Raven._processException('TypeError', undefined, 'http://example.com', []);
808808
assert.isTrue(Raven._send.called);
809809
});
810+
811+
// `throw ''` scenario. TraceKit always defaults to '' for message and 'null' for name if not parseable
812+
// It's required to preserve minimal (1 frame only) stack on the server and let user to see
813+
// at least something, otherwise whole exception interface will be dropped
814+
// and nothing will allow user to determine where this error came from
815+
it('should override message if neither type or message are present', function() {
816+
this.sinon.stub(Raven, '_send');
817+
818+
Raven._processException(null, '', 'http://example.com', []);
819+
assert.equal(
820+
Raven._send.lastCall.args[0].exception.values[0].value,
821+
'Unrecoverable error caught'
822+
);
823+
});
810824
});
811825

812826
if (supportsPromiseRejectionEvent()) {
@@ -3122,6 +3136,19 @@ describe('Raven (public API)', function() {
31223136
// but wrapped in an array
31233137
assert.deepEqual(fingerprint, ['foo']);
31243138
});
3139+
3140+
it('should get collected if captureMessage was called with an empty string', function() {
3141+
this.sinon.stub(Raven, 'isSetup').returns(true);
3142+
this.sinon.stub(Raven, '_send');
3143+
3144+
function foo() {
3145+
Raven.captureMessage('');
3146+
}
3147+
3148+
foo();
3149+
var data = Raven._send.lastCall.args[0];
3150+
assertSynthetic(data.stacktrace.frames);
3151+
});
31253152
});
31263153
});
31273154

0 commit comments

Comments
 (0)