-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: avoid null deferences #1610
Conversation
@@ -63,7 +63,7 @@ export const formatPercent = (value: number) => { | |||
}; | |||
|
|||
export const formatCoordinate = (value: number) => { | |||
return value.toLocaleString(undefined, { | |||
return value?.toLocaleString(undefined, { |
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 don't think this is correct. The value
parameter should be declared as optional. This will also return undefined
for a zero coordinate value, which seems incorrect since zero is a valid lat/lon value.
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.
value is not optional here. but if it's undefined, I don't want to try to call .toLocaleString()
and crash.
This works fine for 0
. Optional chaining only fails on undefined or null, not other falsy values.
Did I misunderstand?
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 feel that if we're possibly expecting value
to be undefined in the method body. we should declare it in the method signature as well. Otherwise someone might come along this code in the future, assume that the method signature is correct, and accidentally remove the check.
You're right on optional chaining - I forgot that it specifically checks for null/undefined and not just a falsy value.
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.
value
should not be undefined, but I don't want to crash when it is. This seems to mostly come up in hot reloads.
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.
See comment on formatCoordinate
function.
The fixes in Soil ID ranking seem to be for Sentry 5563928079, which is likely the cause of #1694 |
Description
Avoid some null deferences that pop up in debugging.