Page MenuHomePhabricator

API shouldn't log error-level exception for invalid 'formatversion' parameter
Closed, ResolvedPublicPRODUCTION ERROR

Description

In playing with T199941, I mistyped the formatversion= parameter and noticed it logged the user-issue as a server-side error with exception. Seems like something that isn't supposed to happen?

error (1)
type: mediawiki
channel: exception
exception_id: W0@aHgpAIDMAAC@YPYwAAADU
exception.class: ApiUsageException
exception.message:

Unrecognized value for parameter "formatversion": .
trace (1)
#0 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiBase.php(1973): ApiUsageException::newWithMessage(ApiFormatJson, array, string, NULL, NULL)
#1 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiBase.php(1560): ApiBase->dieWithError(array, string)
#2 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiBase.php(1278): ApiBase->parseMultiValue(string, string, boolean, array, NULL, integer, integer)
#3 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiFormatBase.php(156): ApiBase->getParameterFromSettings(string, array, boolean)
#4 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiBase.php(797): ApiFormatBase->getParameterFromSettings(string, array, boolean)
#5 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiFormatJson.php(46): ApiBase->extractRequestParams()
#6 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiFormatBase.php(196): ApiFormatJson->getMimeType()
#7 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(1806): ApiFormatBase->initPrinter(boolean)
#8 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(600): ApiMain->printResult(integer)
#9 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(544): ApiMain->handleException(MWException)
#10 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(506): ApiMain->executeActionWithErrorHandling()
#11 /srv/mediawiki/php-1.32.0-wmf.13/api.php(83): ApiMain->execute()
#12 /srv/mediawiki/w/api.php(3): include(string)
#13 {main}

And from the same request:

error (2)
type: mediawiki
channel: exception
exception_id: W0@aHgpAIDMAAC@YPYwAAADU
exception.class: MWException
exception.message

Language::isValidBuiltInCode must be passed a string, boolean given

#0 /srv/mediawiki/php-1.32.0-wmf.13/languages/Language.php(213): Language::isValidBuiltInCode(boolean)
#1 /srv/mediawiki/php-1.32.0-wmf.13/languages/Language.php(191): Language::newFromCode(boolean)
#2 /srv/mediawiki/php-1.32.0-wmf.13/extensions/Babel/includes/BabelBox/LanguageBabelBox.php(85): Language::factory(boolean)
#3 /srv/mediawiki/php-1.32.0-wmf.13/extensions/Babel/includes/Babel.php(190): MediaWiki\Babel\BabelBox\LanguageBabelBox->render()
#4 /srv/mediawiki/php-1.32.0-wmf.13/extensions/Babel/includes/Babel.php(109): Babel::mGenerateContent(Parser, string, array)
#5 /srv/mediawiki/php-1.32.0-wmf.13/extensions/Babel/includes/Babel.php(47): Babel::mGenerateContentTower(Parser, array)
#6 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3434): Babel::Render(Parser, string, string)
#7 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3138): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#8 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#9 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1626): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#10 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1638): PPTemplateFrame_Hash->getNamedArgument(string)
#11 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3811): PPTemplateFrame_Hash->getArgument(string)
#12 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1131): Parser->argSubstitution(array, PPTemplateFrame_Hash)
#13 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1626): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#14 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1638): PPTemplateFrame_Hash->getNamedArgument(string)
#15 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3811): PPTemplateFrame_Hash->getArgument(string)
#16 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1131): Parser->argSubstitution(array, PPTemplateFrame_Hash)
#17 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3056): PPFrame_Hash->expand(PPNode_Hash_Tree)
#18 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#19 /srv/mediawiki/php-1.32.0-wmf.13/extensions/ParserFunctions/includes/ExtParserFunctions.php(200): PPFrame_Hash->expand(PPNode_Hash_Tree)
#20 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3434): ExtParserFunctions::switchObj(Parser, PPTemplateFrame_Hash, array)
#21 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3138): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#22 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#23 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3313): PPFrame_Hash->expand(PPNode_Hash_Tree)
#24 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#25 /srv/mediawiki/php-1.32.0-wmf.13/extensions/ParserFunctions/includes/ExtParserFunctions.php(225): PPFrame_Hash->expand(PPNode_Hash_Tree)
#26 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3434): ExtParserFunctions::switchObj(Parser, PPTemplateFrame_Hash, array)
#27 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3138): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#28 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#29 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3313): PPFrame_Hash->expand(PPNode_Hash_Tree)
#30 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#31 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1546): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#32 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(3310): PPTemplateFrame_Hash->cachedExpand(string, PPNode_Hash_Tree)
#33 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPFrame_Hash)
#34 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(2953): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#35 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(1297): Parser->replaceVariables(string)
#36 /srv/mediawiki/php-1.32.0-wmf.13/includes/parser/Parser.php(446): Parser->internalParse(string)
#37 /srv/mediawiki/php-1.32.0-wmf.13/includes/StubObject.php(112): Parser->parse(string, Title, ParserOptions, boolean, boolean, NULL)
#38 /srv/mediawiki/php-1.32.0-wmf.13/includes/StubObject.php(138): StubObject->_call(string, array)
#39 /srv/mediawiki/php-1.32.0-wmf.13/includes/content/WikitextContent.php(323): StubObject->__call(string, array)
#40 /srv/mediawiki/php-1.32.0-wmf.13/includes/content/AbstractContent.php(516): WikitextContent->fillParserOutput(Title, NULL, ParserOptions, boolean, ParserOutput)
#41 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiParse.php(268): AbstractContent->getParserOutput(Title, NULL, ParserOptions)
#42 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(1584): ApiParse->execute()
#43 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(535): ApiMain->executeAction()
#44 /srv/mediawiki/php-1.32.0-wmf.13/includes/api/ApiMain.php(506): ApiMain->executeActionWithErrorHandling()
#45 /srv/mediawiki/php-1.32.0-wmf.13/api.php(83): ApiMain->execute()
#46 /srv/mediawiki/w/api.php(3): include(string)
#47 {main}

Event Timeline

Krinkle updated the task description. (Show Details)

When the printer throws an error, ApiMain tries to recreate the printer and sets a flag to have it ignore the request parameters to avoid exactly this situation. But it turns out that ApiModuleManager caching was causing it to reuse the same object instead of creating a new one.

That used to work anyway for this situation because before 24be43b9a the validation error would prevent the processed parameters from being cached in the instance so the attempt to re-print after setting the "ignore request parameters" flag would have to reprocess the parameters and see the flag. 24be43b9a had to change that behavior so it started caching the validation errors, exposing the bug mentioned above.

Change 446821 had a related patch set uploaded (by Anomie; owner: Anomie):
[mediawiki/core@master] ApiMain: Always create a new printer in getPrinterByName()

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

Change 446821 merged by jenkins-bot:
[mediawiki/core@master] ApiMain: Always create a new printer in getPrinterByName()

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

mmodell changed the subtype of this task from "Task" to "Production Error".Aug 28 2019, 11:08 PM