Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that the {} doesn't throw a type error. Do you think we should add
avatarSource is string | undefined
like we do here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it returns if avatar source is string or undefined and if we should use default avatar. It does not necessarily ensure type. we can have something like -
Let's discuss in slack and do as a follow up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just add a empty object check in
ReportUtils.getIcons
. When it's empty, we can just use theFallbackAvatar
. Right now empty object is still a valid for theAvatarSource
type so someone can still re-introduce this bug without noticing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't fully solve the concern of reintroducing this crash again, no? There are other places too where we call Avatar methods -
getAvatar()
and AvatarSource argument type is {} and it is returned as {} causing such crashesRight, how about throwing as mentioned above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this crash it would. The root problem was that
ReportUtils.getIcons
is returning an invalidsource
when given certain params. I think we should just fix that by validating the params and returning the fallback if validation fails. We can write aisValidAvatarSource
function and use it where needed.I'm not sure how that helps honestly. Does that not also crash the app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with this. I meant if we have this logic at lower level function like getAvatar(), it would help us to catch all errors as
ReportUtils.getIcons
was getting defaultIcon argument that resulted fromgetAvatar()
Sounds good 👍
and if the check fails, we return avatarSource as empty string, correct?
Yes, if someone added such param then it would throw the error so we can catch it during testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay I see. I think we should probably validate in both places just to be safe. For
ReportUtils.getIcons
I think we should just return theFallbackAvatar
when the given AvatarSource is invalid. I'm not sure about other places though.We're already throwing an error and crashing the app as it is. So I don't think throwing a different error will make the bug more noticeable in testing. I think we should always avoid crashing the app and just log the error instead. That way we can still catch it in testing and if we don't, the app isn't crashing for users.