Skip to content

Commit 26717a6

Browse files
committed
Truncate error message at 100 chars
1 parent cce3f41 commit 26717a6

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/raven.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,9 @@ function processException(type, message, fileurl, lineno, frames, options) {
526526
};
527527
}
528528

529+
// Truncate the message to a max of characters
530+
message = truncate(message, 100);
531+
529532
if (globalOptions.ignoreUrls && globalOptions.ignoreUrls.test(fileurl)) return;
530533
if (globalOptions.whitelistUrls && !globalOptions.whitelistUrls.test(fileurl)) return;
531534

@@ -557,6 +560,14 @@ function objectMerge(obj1, obj2) {
557560
return obj1;
558561
}
559562

563+
function truncate(str, max) {
564+
str = str.substr(0, max);
565+
if (str.length === max) {
566+
str += '…';
567+
}
568+
return str;
569+
}
570+
560571
function getHttpData() {
561572
var http = {
562573
url: document.location.href,

test/raven.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ describe('globals', function() {
200200
});
201201
});
202202

203+
describe('truncate', function() {
204+
it('should work as advertised', function() {
205+
assert.equal(truncate('lolol', 3), 'lol…');
206+
assert.equal(truncate('lolol', 10), 'lolol');
207+
});
208+
});
209+
203210
describe('isSetup', function() {
204211
it('should return false with no JSON support', function() {
205212
globalServer = 'http://localhost/';

0 commit comments

Comments
 (0)