-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 timezone crash #8485
Fix timezone crash #8485
Conversation
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 have 1-2 non-blocking suggestions. Thanks for getting to this so quickly.
timeZone, | ||
}).format(new Date(value)); | ||
} catch (error) { | ||
logDebug('Failed to format date', {locale, timezone}, error); |
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.
Shouldn't this be logError? This would have cause a crash if wasn't caught.
It would add entry into sentry with proper Error
category.
logDebug('Failed to format date', {locale, timezone}, error); | |
logError('Failed FormattedDate to format date', {locale, timezone}, error); |
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.
@rahimrahman Would it be better to check if the timeZone name is valid first, and maybe default to the server's timezone (or something), rather than try catching?
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.
@cpoile 0/5. I'm okay with the try..catch. Just asking about the logError vs logDebug.
With the try..catch, it won't crash anymore so doing the Intl.DateTimeFormat would validate all the props.
@@ -46,7 +46,7 @@ if (global.HermesInternal) { | |||
require('@formatjs/intl-pluralrules/polyfill-force'); | |||
require('@formatjs/intl-numberformat/polyfill-force'); | |||
require('@formatjs/intl-datetimeformat/polyfill-force'); | |||
require('@formatjs/intl-datetimeformat/add-golden-tz'); | |||
require('@formatjs/intl-datetimeformat/add-all-tz'); |
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.
What's the diff between golden and all?
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.
Looked up, besides the obvious:
Golden: contains popular set of timezones from IANA database
@@ -1,5 +1,11 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`<FormattedDate/> should default when timezone is not found 1`] = ` |
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.
This is the only time I'm okay with snapshots!
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.
Indeed -- unit tests that actually test functionality :) 👍
...format, | ||
}).format(new Date(value)); | ||
} catch (error) { | ||
logDebug('Failed to format default date', {locale}, error); |
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.
Same.
logDebug('Failed to format default date', {locale}, error); | |
logError('Failed FormattedDate to format default date', {locale, timezone}, error); |
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'll approve conditional on Rahim's comments. Also assuming that you've checked (and wrapped as needed) all other uses of DatTimeFormat
as well?
Awesome, thanks @larkox !
@@ -1,5 +1,11 @@ | |||
// Jest Snapshot v1, https://goo.gl/fbAQLP | |||
|
|||
exports[`<FormattedDate/> should default when timezone is not found 1`] = ` |
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.
Indeed -- unit tests that actually test functionality :) 👍
timeZone, | ||
}).format(new Date(value)); | ||
} catch (error) { | ||
logDebug('Failed to format date', {locale, timezone}, error); |
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.
@rahimrahman Would it be better to check if the timeZone name is valid first, and maybe default to the server's timezone (or something), rather than try catching?
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.
Verified fix on PR build for Android and iOS. Verified setting the timezone to previously crashing timezones and then accessing channels did not crash the app. Also ran through quick smoke tests of general functionality including SSO and push notifications. No issues found. 👍
/cherry-pick release-2.24 |
Cherry pick is scheduled. |
/cherry-pick release-2.25 |
Error trying doing the automated Cherry picking. Please do this manually
|
Cherry pick is scheduled. |
Error trying doing the automated Cherry picking. Please do this manually
|
* Fix timezone crash by adding all timezones to the polyfill * update snapshots; be careful about undefined: diff on local vs CI * one more that's different locally vs CI * i18n --------- Co-authored-by: Christopher Poile <cpoile@gmail.com>
* Fix timezone crash by adding all timezones to the polyfill * update snapshots; be careful about undefined: diff on local vs CI * one more that's different locally vs CI * i18n --------- Co-authored-by: Christopher Poile <cpoile@gmail.com>
* Fix timezone crash by adding all timezones to the polyfill * update snapshots; be careful about undefined: diff on local vs CI * one more that's different locally vs CI * i18n --------- Co-authored-by: Christopher Poile <cpoile@gmail.com>
Summary
Fix crash that occurs on several timezones.
Ticket Link
Fix https://mattermost.atlassian.net/browse/MM-62298
Fix #8423
Release Note