Page MenuHomePhabricator

"ResourceLoader\Context::encodeJson: Malformed UTF-8 characters" in mw.config data from Flow
Open, LowPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded
exception.trace
from /srv/mediawiki/php-1.41.0-wmf.30/includes/ResourceLoader/Context.php(513)
#0 [internal function]: MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.41.0-wmf.30/includes/ResourceLoader/Context.php(513): trigger_error(string, integer)
#2 /srv/mediawiki/php-1.41.0-wmf.30/includes/ResourceLoader/ClientHtml.php(299): MediaWiki\ResourceLoader\Context->encodeJson(array)
#3 /srv/mediawiki/php-1.41.0-wmf.30/includes/Output/OutputPage.php(3511): MediaWiki\ResourceLoader\ClientHtml->getHeadHtml(string)
#4 /srv/mediawiki/php-1.41.0-wmf.30/includes/skins/SkinMustache.php(98): MediaWiki\Output\OutputPage->headElement(MediaWiki\Skins\Vector\SkinVector22)
#5 /srv/mediawiki/php-1.41.0-wmf.30/includes/skins/SkinTemplate.php(174): SkinMustache->generateHTML()
#6 /srv/mediawiki/php-1.41.0-wmf.30/includes/Output/OutputPage.php(2947): SkinTemplate->outputPage()
#7 /srv/mediawiki/php-1.41.0-wmf.30/includes/MediaWiki.php(978): MediaWiki\Output\OutputPage->output(boolean)
#8 /srv/mediawiki/php-1.41.0-wmf.30/includes/MediaWiki.php(613): MediaWiki->main()
#9 /srv/mediawiki/php-1.41.0-wmf.30/index.php(50): MediaWiki->run()
#10 /srv/mediawiki/php-1.41.0-wmf.30/index.php(46): wfIndexMain()
#11 /srv/mediawiki/w/index.php(3): require(string)
#12 {main}
Impact
Notes

6 errors in the last 24 hours
76 errors in the last 14 days
Errors come from three different URLs from ZH Wiki and most of those url's point to a user talk page.

In the past, we had a similar issue {T331641: Context::encodeJson partially failed (invalid modules parameter)} but this one is triggered by SkinTemplate->outputPage() where the previous one was triggered via RL load.php script.

Event Timeline

brennen changed the subtype of this task from "Bug Report" to "Production Error".Oct 19 2023, 3:37 PM
matmarex subscribed.

This seems to be caused by Flow. Visiting the page https://zh.wikipedia.org/wiki/Topic:Xqqol71sqvayiiuf consistently causes the error. There's probably some malformed data in the huge 'wgFlowData' blob it adds to the page, but I don't know what it is.

I found the bad piece of data, it's obvious in the API response: https://zh.wikipedia.org/w/api.php?action=flow&format=jsonfm&submodule=view-topic-history&page=Topic%3AXqqol71sqvayiiuf&formatversion=2

At the end of "moderated-reason" and "moderateReason" (not sure what's the difference), there is a "�" U+FFFD REPLACEMENT CHARACTER, which usually indicates that the text has been cut off in the middle of a multi-byte character – and the text up to this character is 254 bytes, and 255 is a common length limit for various fields in MediaWiki.

Tgr subscribed.

Let's decline then, minor Flow bugs aren't really worth fixing since the extension is deprecated and will probably be removed at some point.

Krinkle triaged this task as Low priority.

Re-opening since this is an unresolved re-producible production error. Without the task open, it's going to get duplicate reports, since our process (https://wikitech.wikimedia.org/wiki/MediaWiki_Engineering/Guides/Monitor_production_errors) is desiged around tracking these as open tasks. It seems impractical to include closed tasks, as that widens the scope for false positives significantly.

I've lowered the priority instead. It is for the Growth team to decide how/if to handle this. I will note that frequency and ease of reproducing these, does contribute to noise and thus lowers the standard for everyone, as it is harder to discover issues less frequent than the collectively accepted baseline. This includes e.g. monitoring alerts and deployment checks, in terms automatically detecting and catching regressions vs tolerated noise below the baseline.

Krinkle renamed this task from ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded to "ResourceLoader\Context::encodeJson: Malformed UTF-8 characters" in mw.config data from Flow .Mar 3 2025, 8:00 AM
Krinkle added subscribers: Reedy, Pppery.

Still in 1.45.0-wmf.9:

Error
  • service.version: 1.45.0-wmf.9
  • timestamp: 2025-07-09T17:17:21.922Z
  • labels.phpversion: 8.1.32
  • trace.id: 8f39a192-6423-42bc-acac-718621c78101
  • Find trace.id in Logstash
labels.normalized_message
[{reqId}] {exception_url}   PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded
FrameLocationCall
from/srv/mediawiki/php-1.45.0-wmf.9/includes/ResourceLoader/Context.php(490)
#0[internal function]MediaWiki\Exception\MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.45.0-wmf.9/includes/ResourceLoader/Context.php(490)trigger_error(string, int)
#2/srv/mediawiki/php-1.45.0-wmf.9/includes/ResourceLoader/ClientHtml.php(311)MediaWiki\ResourceLoader\Context->encodeJson(array)
#3/srv/mediawiki/php-1.45.0-wmf.9/includes/Output/OutputPage.php(3920)MediaWiki\ResourceLoader\ClientHtml->getHeadHtml(string)
#4/srv/mediawiki/php-1.45.0-wmf.9/includes/skins/Skin.php(686)MediaWiki\Output\OutputPage->headElement(MediaWiki\Minerva\Skins\SkinMinerva)
#5/srv/mediawiki/php-1.45.0-wmf.9/includes/Output/OutputPage.php(3291)MediaWiki\Skin\Skin->outputPageFinal(MediaWiki\Output\OutputPage)
#6/srv/mediawiki/php-1.45.0-wmf.9/includes/actions/ActionEntryPoint.php(160)MediaWiki\Output\OutputPage->output(bool)
#7/srv/mediawiki/php-1.45.0-wmf.9/includes/MediaWikiEntryPoint.php(198)MediaWiki\Actions\ActionEntryPoint->execute()
#8/srv/mediawiki/php-1.45.0-wmf.9/index.php(58)MediaWiki\MediaWikiEntryPoint->run()
#9/srv/mediawiki/w/index.php(3)require(string)
#10{main}

Seems like still happening as of 1.46.0-wmf.15

Error
  • service.version: 1.46.0-wmf.15
  • timestamp: 2026-02-12T13:04:22.674Z
  • labels.phpversion: 8.3.30
  • trace.id: c823c319-df8d-44b3-95a7-7d2f5ed9d375
  • Find trace.id in Logstash
labels.normalized_message
[{reqId}] {exception_url}   PHP Warning: MediaWiki\ResourceLoader\Context::encodeJson partially failed: Malformed UTF-8 characters, possibly incorrectly encoded
FrameLocationCall
from/srv/mediawiki/php-1.46.0-wmf.15/includes/ResourceLoader/Context.php(476)
#0[internal function]MediaWiki\Exception\MWExceptionHandler::handleError(int, string, string, int)
#1/srv/mediawiki/php-1.46.0-wmf.15/includes/ResourceLoader/Context.php(476)trigger_error(string, int)
#2/srv/mediawiki/php-1.46.0-wmf.15/includes/ResourceLoader/ClientHtml.php(297)MediaWiki\ResourceLoader\Context->encodeJson(array)
#3/srv/mediawiki/php-1.46.0-wmf.15/includes/Output/OutputPage.php(3897)MediaWiki\ResourceLoader\ClientHtml->getHeadHtml(string)
#4/srv/mediawiki/php-1.46.0-wmf.15/includes/Skin/Skin.php(686)MediaWiki\Output\OutputPage->headElement(MediaWiki\Skins\Vector\SkinVector22)
#5/srv/mediawiki/php-1.46.0-wmf.15/includes/Output/OutputPage.php(3307)MediaWiki\Skin\Skin->outputPageFinal(MediaWiki\Output\OutputPage)
#6/srv/mediawiki/php-1.46.0-wmf.15/includes/Actions/ActionEntryPoint.php(161)MediaWiki\Output\OutputPage->output(bool)
#7/srv/mediawiki/php-1.46.0-wmf.15/includes/MediaWikiEntryPoint.php(180)MediaWiki\Actions\ActionEntryPoint->execute()
#8/srv/mediawiki/php-1.46.0-wmf.15/index.php(44)MediaWiki\MediaWikiEntryPoint->run()
#9/srv/mediawiki/w/index.php(3)require(string)
#10{main}