Skip to content

Commit 50ff869

Browse files
committed
Merge pull request #156 from getsentry/fix-155
Coerce error.name to string before assigning as type (fixes #155)
2 parents 9d98b22 + 9895d29 commit 50ff869

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/parsers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ module.exports.parseText = function parseText(message, kwargs) {
1313

1414
module.exports.parseError = function parseError(err, kwargs, cb) {
1515
utils.parseStack(err, function(frames) {
16+
var name = err.name + '';
1617
if (typeof kwargs.message === 'undefined') {
17-
kwargs.message = err.name + ': ' + (err.message || '<no message>');
18+
kwargs.message = name + ': ' + (err.message || '<no message>');
1819
}
1920
kwargs.exception = [{
20-
type: err.name,
21+
type: name,
2122
value: err.message,
2223
stacktrace: {
2324
frames: frames
@@ -36,7 +37,7 @@ module.exports.parseError = function parseError(err, kwargs, cb) {
3637
}
3738
if (extraErrorProps) {
3839
kwargs.extra = kwargs.extra || {};
39-
kwargs.extra[err.name] = extraErrorProps;
40+
kwargs.extra[name] = extraErrorProps;
4041
}
4142

4243
for (var n = frames.length - 1; n >= 0; n--) {
@@ -166,4 +167,4 @@ module.exports.parseRequest = function parseRequest(req, kwargs) {
166167
kwargs.request = http;
167168

168169
return kwargs;
169-
};
170+
};

test/raven.parsers.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,19 @@ describe('raven.parsers', function() {
445445
});
446446
});
447447

448+
it('should parse Error with non-string type', function(done) {
449+
var err = new Error();
450+
err.name = {};
451+
raven.parsers.parseError(err, {}, function(parsed) {
452+
parsed.message.should.equal('[object Object]: <no message>');
453+
parsed.should.have.property('exception');
454+
parsed.exception[0].type.should.equal('[object Object]');
455+
parsed.exception[0].value.should.equal('');
456+
parsed.exception[0].stacktrace.should.have.property('frames');
457+
done();
458+
});
459+
});
460+
448461
it('should parse thrown Error', function(done) {
449462
try {
450463
throw new Error('Derp');

0 commit comments

Comments
 (0)