Stats: avoid trying to access formatter for unavailable locale#43396
Stats: avoid trying to access formatter for unavailable locale#43396
Conversation
This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example.
There was a problem hiding this comment.
Pull Request Overview
This pull request prevents PHP fatal errors in the Stats column by ensuring that an invalid locale is replaced with a fallback locale ("en_US") when constructing the NumberFormatter.
- Added a locale validity check with a fallback in the get_formatter method.
- Included a changelog entry detailing the fix for the locale issue.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| projects/packages/stats-admin/src/class-admin-post-list-column.php | Added a locale availability check and fallback logic in the get_formatter method. |
| projects/packages/stats-admin/changelog/fix-php84-locale-error-stats | Added a changelog entry describing the PHP fatal error fix. |
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
Code Coverage SummaryCoverage changed in 1 file.
|
The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3.
kangzj
left a comment
There was a problem hiding this comment.
Works well and looks good! Thanks fixing this 👍
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
* Stats: avoid trying to access formatter for unavailable locale This should avoid errors like: Fatal error: Uncaught ValueError: NumberFormatter::__construct(): Argument #1 ($locale) "skr" is invalid Internal reference: p1746629628168729-slack-CDLH4C1UZ Some of the locale codes we pass to NumberFormatter are not always available. `skr` is a good example. * Extract locale check to speed up locale detection See Automattic/jetpack#43396 (comment) * Get locale with an underscore instead of dash The dash is appropriate to display the language code in HTML, but is not valid ISO 639-3. * Add test for new method * Avoid static analysis error Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/14900742224 Upstream-Ref: Automattic/jetpack@bdb2551
Proposed changes:
This should avoid errors like:
Some of the locale codes we pass to NumberFormatter are not always available.
skris a good example. I've detailed this problem in this issue: php/php-src#18515Other information:
Jetpack product discussion
Internal reference: p1746629628168729-slack-CDLH4C1UZ
Does this pull request change what data or activity we track or use?
Testing instructions: