Skip to content
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

Merged
merged 6 commits into from
Jan 16, 2025
Merged

Fix timezone crash #8485

merged 6 commits into from
Jan 16, 2025

Conversation

larkox
Copy link
Contributor

@larkox larkox commented Jan 16, 2025

Summary

Fix crash that occurs on several timezones.

Ticket Link

Fix https://mattermost.atlassian.net/browse/MM-62298
Fix #8423

Release Note

Fix crash when using certain timezones

@larkox larkox added 2: Dev Review Requires review by a core commiter 3: QA Review Requires review by a QA tester labels Jan 16, 2025
@larkox larkox requested review from a team and cpoile and removed request for a team January 16, 2025 16:38
@larkox larkox requested a review from rahimrahman January 16, 2025 16:38
Copy link
Contributor

@rahimrahman rahimrahman left a 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);
Copy link
Contributor

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.

Suggested change
logDebug('Failed to format date', {locale, timezone}, error);
logError('Failed FormattedDate to format date', {locale, timezone}, error);

Copy link
Member

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?

Copy link
Contributor

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');
Copy link
Contributor

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?

Copy link
Contributor

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`] = `
Copy link
Contributor

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!

Copy link
Member

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

Suggested change
logDebug('Failed to format default date', {locale}, error);
logError('Failed FormattedDate to format default date', {locale, timezone}, error);

Copy link
Member

@cpoile cpoile left a 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`] = `
Copy link
Member

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);
Copy link
Member

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?

@lindalumitchell lindalumitchell added the Build Apps for PR Build the mobile app for iOS and Android to test label Jan 16, 2025
@lindalumitchell lindalumitchell added Build Apps for PR Build the mobile app for iOS and Android to test and removed Build Apps for PR Build the mobile app for iOS and Android to test labels Jan 16, 2025
Copy link
Contributor

@lindalumitchell lindalumitchell left a 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. 👍

@lindalumitchell lindalumitchell removed Build Apps for PR Build the mobile app for iOS and Android to test 3: QA Review Requires review by a QA tester labels Jan 16, 2025
@jwilander jwilander merged commit 592b380 into main Jan 16, 2025
15 checks passed
@jwilander jwilander deleted the fixTimezoneCrash branch January 16, 2025 22:29
@jwilander jwilander added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core commiter labels Jan 16, 2025
@amyblais
Copy link
Member

/cherry-pick release-2.24

@mattermost-build
Copy link
Contributor

Cherry pick is scheduled.

@amyblais
Copy link
Member

/cherry-pick release-2.25

@mattermost-build
Copy link
Contributor

Error trying doing the automated Cherry picking. Please do this manually

+++ Updating remotes...
Fetching upstream
hostfile_replace_entries: mkstemp: Read-only file system
update_known_hosts: hostfile_replace_entries failed for /app/.ssh/known_hosts: Read-only file system
From github.com:mattermost/mattermost-mobile
 * [new branch]          actions-websockets-tests -> upstream/actions-websockets-tests
   d1d3fda83..592b3805f  main         -> upstream/main
   1b5ec1e00..5615405e3  release-2.25 -> upstream/release-2.25
Fetching upstream
hostfile_replace_entries: mkstemp: Read-only file system
update_known_hosts: hostfile_replace_entries failed for /app/.ssh/known_hosts: Read-only file system
+++ Updating remotes done...
+++ Creating local branch automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.24-1737095371
Switched to a new branch 'automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.24-1737095371'
Branch 'automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.24-1737095371' set up to track remote branch 'release-2.24' from 'upstream'.

+++ About to attempt cherry pick of PR #8485 with merge commit 592b3805f1240794915c1acbd7819f0238fc4abe.

Auto-merging assets/base/i18n/en.json
Auto-merging package-lock.json
CONFLICT (content): Merge conflict in package-lock.json
Auto-merging package.json
CONFLICT (content): Merge conflict in package.json
error: could not apply 592b3805f... Fix timezone crash (#8485)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

+++ Conflicts detected:

UU package-lock.json
UU package.json
Aborting.

+++ Aborting in-progress git cherry-pick.

+++ Returning you to the master branch and cleaning up.

@mattermost-build
Copy link
Contributor

Cherry pick is scheduled.

@mattermost-build
Copy link
Contributor

Error trying doing the automated Cherry picking. Please do this manually

+++ Updating remotes...
Fetching upstream
hostfile_replace_entries: mkstemp: Read-only file system
update_known_hosts: hostfile_replace_entries failed for /app/.ssh/known_hosts: Read-only file system
Fetching upstream
hostfile_replace_entries: mkstemp: Read-only file system
update_known_hosts: hostfile_replace_entries failed for /app/.ssh/known_hosts: Read-only file system
+++ Updating remotes done...
+++ Creating local branch automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.25-1737095374
Switched to a new branch 'automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.25-1737095374'
Branch 'automated-cherry-pick-of-mattermost-mobile-#8485-upstream-release-2.25-1737095374' set up to track remote branch 'release-2.25' from 'upstream'.

+++ About to attempt cherry pick of PR #8485 with merge commit 592b3805f1240794915c1acbd7819f0238fc4abe.

Auto-merging package-lock.json
CONFLICT (content): Merge conflict in package-lock.json
error: could not apply 592b3805f... Fix timezone crash (#8485)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

+++ Conflicts detected:

UU package-lock.json
Aborting.

+++ Aborting in-progress git cherry-pick.

+++ Returning you to the master branch and cleaning up.

@amyblais amyblais added this to the v2.24.0 milestone Jan 17, 2025
larkox added a commit to larkox/mattermost-mobile that referenced this pull request Jan 17, 2025
* 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>
amyblais pushed a commit that referenced this pull request Jan 17, 2025
* 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>
larkox added a commit that referenced this pull request Jan 17, 2025
* 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>
amyblais pushed a commit that referenced this pull request Jan 17, 2025
* 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>
yasserfaraazkhan pushed a commit that referenced this pull request Jan 17, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid TimeZoneName error at launch of direct message or channel
8 participants