Skip to content

Commit eaafc0d

Browse files
committed
Move trimming logic after data callbacks
This makes sure we trim the data packet before being sent since the dataCallback is freely able to modify the packet
1 parent 18fbd68 commit eaafc0d

File tree

2 files changed

+106
-57
lines changed

2 files changed

+106
-57
lines changed

src/raven.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,7 @@ function processException(type, message, fileurl, lineno, frames, options) {
668668
if (!!globalOptions.ignoreErrors.test && globalOptions.ignoreErrors.test(message)) return;
669669

670670
message += '';
671-
message = truncate(message, globalOptions.maxMessageLength);
672-
673671
fullMessage = type + ': ' + message;
674-
fullMessage = truncate(fullMessage, globalOptions.maxMessageLength);
675672

676673
if (frames && frames.length) {
677674
fileurl = frames[0].filename || fileurl;
@@ -723,6 +720,19 @@ function truncate(str, max) {
723720
return str.length <= max ? str : str.substr(0, max) + '\u2026';
724721
}
725722

723+
function trimPacket(data) {
724+
// For now, we only want to truncate the two different messages
725+
// but this could/should be expanded to just trim everything
726+
var max = globalOptions.maxMessageLength;
727+
data.message = truncate(data.message, max);
728+
if (data.exception) {
729+
var exception = data.exception.values[0];
730+
exception.value = truncate(exception.value, max);
731+
}
732+
733+
return data;
734+
}
735+
726736
function now() {
727737
return +new Date();
728738
}
@@ -799,6 +809,9 @@ function send(data) {
799809
// Set lastEventId after we know the error should actually be sent
800810
lastEventId = data.event_id || (data.event_id = uuid4());
801811

812+
// Try and clean up the packet before sending by truncating long values
813+
data = trimPacket(data);
814+
802815
logDebug('debug', 'Raven about to send:', data);
803816

804817
if (!isSetup()) return;

0 commit comments

Comments
 (0)