From 1cfe3cdfc82f038ca2605fb0dfa9c2a9a0e299e6 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Thu, 24 Aug 2023 14:58:10 -0700 Subject: [PATCH] =?UTF-8?q?fix(core):=20=F0=9F=90=9B=20catch=20IntlExcepti?= =?UTF-8?q?on=20for=20NumberFormatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should at least avoid Citizen throwing an exception. However, it won't address the root cause of the issue. Closes #474 --- includes/Partials/Drawer.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/includes/Partials/Drawer.php b/includes/Partials/Drawer.php index ffaf2c281..f98ef5c7e 100644 --- a/includes/Partials/Drawer.php +++ b/includes/Partials/Drawer.php @@ -26,6 +26,7 @@ namespace MediaWiki\Skins\Citizen\Partials; use Exception; +use NumberFormatter; /** * Drawer partial of Skin Citizen @@ -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 ) {