diff options
author | Timo Tijhof <krinkle@fastmail.com> | 2023-02-14 23:40:20 +0000 |
---|---|---|
committer | Timo Tijhof <krinkle@fastmail.com> | 2023-02-14 23:40:20 +0000 |
commit | 2ab050f67b7a1a61f95b370571eb8a6791aefa82 (patch) | |
tree | 91497c4201fd4b4c37bc223607aaaa58523f2edb /includes/ResourceLoader/Context.php | |
parent | 756a32f81d579f353dc73c507d87e505470881c4 (diff) | |
download | mediawikicore-2ab050f67b7a1a61f95b370571eb8a6791aefa82.tar.gz mediawikicore-2ab050f67b7a1a61f95b370571eb8a6791aefa82.zip |
ResourceLoader: Permit partial failure of encodeJson() and add logging
Similar to the exception thrown by ResourceLoader::makeConfigSetScript,
but non-fatal so as to generally allow more things to continue working
without it being silent and without giving up visibility through
Logstash.
Bug: T329330
Change-Id: I89832142b55ec0f4d1168314a897624e13ac8a0f
Diffstat (limited to 'includes/ResourceLoader/Context.php')
-rw-r--r-- | includes/ResourceLoader/Context.php | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/includes/ResourceLoader/Context.php b/includes/ResourceLoader/Context.php index 59f76d515402..56475d7c84e9 100644 --- a/includes/ResourceLoader/Context.php +++ b/includes/ResourceLoader/Context.php @@ -502,12 +502,17 @@ class Context implements MessageLocalizer { // and allows URLs to mostly remain readable. $jsonFlags = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | + JSON_PARTIAL_OUTPUT_ON_ERROR | JSON_HEX_TAG | JSON_HEX_AMP; if ( $this->getDebug() ) { $jsonFlags |= JSON_PRETTY_PRINT; } - return json_encode( $data, $jsonFlags ); + $json = json_encode( $data, $jsonFlags ); + if ( json_last_error() !== JSON_ERROR_NONE ) { + trigger_error( __METHOD__ . ' partially failed: ' . json_last_error_msg(), E_USER_WARNING ); + } + return $json; } } |