Page MenuHomePhabricator

MWException: Wikibase\Lib\LanguageWithConversion::validateLanguageCode: invalid language code core-recon/wd-recon-lang
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   MWException: Wikibase\Lib\LanguageWithConversion::validateLanguageCode: invalid language code core-recon/wd-recon-lang
exception.trace
from /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/lib/includes/LanguageWithConversion.php(81)
#0 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/lib/includes/LanguageFallbackChainFactory.php(96): Wikibase\Lib\LanguageWithConversion::validateLanguageCode(string)
#1 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/lib/includes/Formatters/OutputFormatValueFormatterFactory.php(114): Wikibase\Lib\LanguageFallbackChainFactory->newFromLanguageCode(string)
#2 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/lib/includes/Formatters/OutputFormatSnakFormatterFactory.php(94): Wikibase\Lib\Formatters\OutputFormatValueFormatterFactory->applyLanguageDefaults(ValueFormatters\FormatterOptions)
#3 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(218): Wikibase\Lib\Formatters\OutputFormatSnakFormatterFactory->getSnakFormatter(string, ValueFormatters\FormatterOptions)
#4 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(176): Wikibase\Repo\Api\FormatSnakValue->getSnakFormatter(array)
#5 /srv/mediawiki/php-1.40.0-wmf.25/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(145): Wikibase\Repo\Api\FormatSnakValue->formatValue(array, DataValues\TimeValue, NULL)
#6 /srv/mediawiki/php-1.40.0-wmf.25/includes/api/ApiMain.php(1903): Wikibase\Repo\Api\FormatSnakValue->execute()
#7 /srv/mediawiki/php-1.40.0-wmf.25/includes/api/ApiMain.php(880): ApiMain->executeAction()
#8 /srv/mediawiki/php-1.40.0-wmf.25/includes/api/ApiMain.php(851): ApiMain->executeActionWithErrorHandling()
#9 /srv/mediawiki/php-1.40.0-wmf.25/api.php(90): ApiMain->execute()
#10 /srv/mediawiki/php-1.40.0-wmf.25/api.php(45): wfApiMain()
#11 /srv/mediawiki/w/api.php(3): require(string)
#12 {main}
Notes

Occasional bursts of errors observed on Wikidata for 1.40.0-wmf.24 and 1.40.0-wmf.25 First time it was seen was Friday the 24th

https://logstash.wikimedia.org/goto/1c6a262517dd099d94dcaf7e12e34a2d

Details

Request URL
https://www.wikidata.org/w/api.php?_=*&action=wbformatvalue&callback=*&datavalue=*&format=*&generate=*&options=*&property=*

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Can be reproduced locally with something like { "lang": "core-recon/wd-recon-lang" } in the options parameter, e.g.:

{
	"action": "wbformatvalue",
	"format": "json",
	"generate": "text/x-wiki",
	"datavalue": "{\"type\": \"string\", \"value\": \"\"}",
	"datatype": "string",
	"options": "{\"lang\": \"core-recon/wd-recon-lang\"}",
	"formatversion": "2"
}

Feels similar to T323778: [ACTION-API] [TECH] Wikibase doesn’t validate formatter options, can crash with different TypeErrors in spirit, though we’re talking about a different kind of validation here.

I can't reproduce the problem because I only saw this after visiting the link:

Screenshot_20230301_201423.jpg (2×1 px, 668 KB)

While we should of course handle this without crashing, it’s also clearly not a valid request: the code that is making these API requests is also broken. From GitHub search, wd-recon-lang seems to come from OpenRefine, especially the preview-renderer:

var params = {
    action: 'wbformatvalue',
    generate: 'text/html',
    datavalue: jsonValue,
    options: '{"lang":"'+$.i18n('core-recon/wd-recon-lang')+'"}',
    format: 'json'
};

I’m guessing $.i18n() falls back to the message key itself when the message isn’t defined for whatever reason, and that’s how we get these requests. CCing @Pintoch just FYI: probably better to fall back to en in that case.

Change 893506 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/extensions/Wikibase@master] Replace exception class in LanguageWithConversion

https://gerrit.wikimedia.org/r/893506

Thanks for the heads up, I have opened an issue about it on OpenRefine's side: https://github.com/OpenRefine/OpenRefine/issues/5658

Change 893506 merged by jenkins-bot:

[mediawiki/extensions/Wikibase@master] Replace exception class in LanguageWithConversion

https://gerrit.wikimedia.org/r/893506

Lucas_Werkmeister_WMDE claimed this task.

Seems to be fixed in wmf.13.