Skip to content

Conversation

kamilogorek
Copy link
Contributor

Fixes #1275

@kamilogorek kamilogorek requested a review from a team April 10, 2018 18:00
Copy link
Contributor

@MaxBittker MaxBittker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good - i'm just not sure about this behavior? I could be wrong here but i'm not sure allowing these non-string values to pass through is any better than erroring on them.

@@ -492,7 +496,7 @@ describe('utils', function() {
b: 'asd',
c: true,
d: undefined,
e: 'very long string that is definitely ove\u2026',
e: 'very long string that is definitely over\u2026',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you care about this off by one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't realize implementation of truncate that we already had didnt count ellipsis as the character so I just unified it.

if (typeof value === 'string') {
return value.length <= maxLength ? value : value.substr(0, maxLength - 1) + '\u2026';
var maxLength = 40;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this change just tangential, or is it part of the fix?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(thinking it was just a tangential fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was :)

src/utils.js Outdated
@@ -160,7 +160,8 @@ function objectFrozen(obj) {
}

function truncate(str, max) {
return !max || str.length <= max ? str : str.substr(0, max) + '\u2026';
if (typeof str !== 'string' || typeof max !== 'number' || max === 0) return str;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max should never be dynamically resolved - it's taken off of global options. Maybe it could be better to just error here like you were instead of silently not truncating.

Also - the places that truncate gets used, we probably don't want to return anything besides a string - right? If we were to pass through exception.value as an object, does the rest of the code even accept that? maybe it's better to return undefined or an empty string?
we could also coerce str to a string if it's not.

Copy link
Contributor Author

@kamilogorek kamilogorek Apr 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I'll error out if max is not a number.

As for the second question, I think leaving it as is should be fine. Reason being:
a) we won't blow up when we send something else as instead of a string value
b) it'll be captured in the breadcrumb as [object Object] which may indicate that there's something funky going on and that could help developers find the culprit
c) in raw json event that we have available in Sentry, it should contain all the object attributes, which is basically everything someone might need to find out what was the error's value (in case it's some strange object like, in this case, jQuery Error - #1275)

wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, that sounds good to me then! thanks for explaining

@MaxBittker
Copy link
Contributor

approved pending the ‘max’ thing 👍
good fix and nice to dedupe some code

@kamilogorek kamilogorek merged commit 622021e into master Apr 12, 2018
@kamilogorek kamilogorek deleted the truncate-guard branch April 12, 2018 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants