Skip to content

Commit

Permalink
fix(core): 🐛 catch IntlException for NumberFormatter
Browse files Browse the repository at this point in the history
This should at least avoid Citizen throwing an exception.
However, it won't address the root cause of the issue.

Closes #474
  • Loading branch information
alistair3149 committed Aug 24, 2023
1 parent 2c1940c commit 1cfe3cd
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions includes/Partials/Drawer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
namespace MediaWiki\Skins\Citizen\Partials;

use Exception;
use NumberFormatter;

/**
* Drawer partial of Skin Citizen
Expand Down Expand Up @@ -79,11 +80,19 @@ public function getSiteStatsData(): array {
$fmt = null;

// Get NumberFormatter here so that we don't have to call it for every stats
if ( $this->getConfigValue( 'CitizenUseNumberFormatter' ) && class_exists( \NumberFormatter::class ) ) {
if ( $this->getConfigValue( 'CitizenUseNumberFormatter' ) && class_exists( NumberFormatter::class ) ) {
$locale = $skin->getLanguage()->getHtmlCode() ?? 'en_US';
$fmt = new \NumberFormatter( $locale, \NumberFormatter::PADDING_POSITION );
$fmt->setAttribute( \NumberFormatter::ROUNDING_MODE, \NumberFormatter::ROUND_DOWN );
$fmt->setAttribute( \NumberFormatter::MAX_FRACTION_DIGITS, 1 );
try {
$fmt = new NumberFormatter( $locale, NumberFormatter::PADDING_POSITION );
$fmt->setAttribute( NumberFormatter::ROUNDING_MODE, NumberFormatter::ROUND_DOWN );
$fmt->setAttribute( NumberFormatter::MAX_FRACTION_DIGITS, 1 );
} catch ( IntlException $exception ) {
/*
* FIXME: Put a proper log or error message here?
* For some unknown reason, NumberFormatter can throw an IntlException: Constructor failed
* This should allow Citizen to run as usual even if such exception is encountered.
*/
}
}

foreach ( $map as $key => $icon ) {
Expand Down

0 comments on commit 1cfe3cd

Please sign in to comment.