Page MenuHomePhabricator

[S] ApiUsageException: Invalid value for integer parameter "gsroffset".
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
labels.normalized_message
[{reqId}] {exception_url}   ApiUsageException: Invalid value "lk2id" for integer parameter "gsroffset".
error.stack_trace
from /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiUsageException.php(71)
#0 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/Validator/ApiParamValidator.php(335): ApiUsageException::newWithMessage(ApiQuerySearch, Message, string, NULL, integer, Wikimedia\ParamValidator\ValidationException)
#1 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/Validator/ApiParamValidator.php(361): MediaWiki\Api\Validator\ApiParamValidator->convertValidationException(ApiQuerySearch, Wikimedia\ParamValidator\ValidationException)
#2 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiBase.php(1119): MediaWiki\Api\Validator\ApiParamValidator->getValue(ApiQuerySearch, string, array, array)
#3 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiBase.php(802): ApiBase->getParameterFromSettings(string, array, boolean)
#4 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiPageSet.php(284): ApiBase->extractRequestParams()
#5 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiPageSet.php(256): ApiPageSet->executeInternal(boolean)
#6 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiQuery.php(683): ApiPageSet->execute()
#7 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiMain.php(1915): ApiQuery->execute()
#8 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiMain.php(861): ApiMain->executeAction()
#9 /srv/mediawiki/php-1.41.0-wmf.18/extensions/MediaSearch/src/Special/SpecialMediaSearch.php(561): ApiMain->execute()
#10 /srv/mediawiki/php-1.41.0-wmf.18/extensions/MediaSearch/src/Special/SpecialMediaSearch.php(235): MediaWiki\Extension\MediaSearch\Special\SpecialMediaSearch->search(string, string, array, integer, string, string)
#11 /srv/mediawiki/php-1.41.0-wmf.18/includes/specialpage/SpecialPage.php(701): MediaWiki\Extension\MediaSearch\Special\SpecialMediaSearch->execute(NULL)
#12 /srv/mediawiki/php-1.41.0-wmf.18/includes/specialpage/SpecialPageFactory.php(1563): SpecialPage->run(NULL)
#13 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(344): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
#14 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(948): MediaWiki->performRequest()
#15 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(597): MediaWiki->main()
#16 /srv/mediawiki/php-1.41.0-wmf.18/index.php(50): MediaWiki->run()
#17 /srv/mediawiki/php-1.41.0-wmf.18/index.php(46): wfIndexMain()
#18 /srv/mediawiki/w/index.php(3): require(string)
#19 {main}
error.stack.previous_trace
from /srv/mediawiki/php-1.41.0-wmf.18/includes/libs/ParamValidator/TypeDef.php(66)
#0 /srv/mediawiki/php-1.41.0-wmf.18/includes/libs/ParamValidator/TypeDef/IntegerDef.php(27): Wikimedia\ParamValidator\TypeDef->failure(string, string, string, array, array)
#1 /srv/mediawiki/php-1.41.0-wmf.18/includes/libs/ParamValidator/ParamValidator.php(609): Wikimedia\ParamValidator\TypeDef\IntegerDef->validate(string, string, array, array)
#2 /srv/mediawiki/php-1.41.0-wmf.18/includes/libs/ParamValidator/ParamValidator.php(551): Wikimedia\ParamValidator\ParamValidator->validateValue(string, string, array, array)
#3 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/Validator/ApiParamValidator.php(359): Wikimedia\ParamValidator\ParamValidator->getValue(string, array, array)
#4 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiBase.php(1119): MediaWiki\Api\Validator\ApiParamValidator->getValue(ApiQuerySearch, string, array, array)
#5 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiBase.php(802): ApiBase->getParameterFromSettings(string, array, boolean)
#6 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiPageSet.php(284): ApiBase->extractRequestParams()
#7 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiPageSet.php(256): ApiPageSet->executeInternal(boolean)
#8 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiQuery.php(683): ApiPageSet->execute()
#9 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiMain.php(1915): ApiQuery->execute()
#10 /srv/mediawiki/php-1.41.0-wmf.18/includes/api/ApiMain.php(861): ApiMain->executeAction()
#11 /srv/mediawiki/php-1.41.0-wmf.18/extensions/MediaSearch/src/Special/SpecialMediaSearch.php(561): ApiMain->execute()
#12 /srv/mediawiki/php-1.41.0-wmf.18/extensions/MediaSearch/src/Special/SpecialMediaSearch.php(235): MediaWiki\Extension\MediaSearch\Special\SpecialMediaSearch->search(string, string, array, integer, string, string)
#13 /srv/mediawiki/php-1.41.0-wmf.18/includes/specialpage/SpecialPage.php(701): MediaWiki\Extension\MediaSearch\Special\SpecialMediaSearch->execute(NULL)
#14 /srv/mediawiki/php-1.41.0-wmf.18/includes/specialpage/SpecialPageFactory.php(1563): SpecialPage->run(NULL)
#15 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(344): MediaWiki\SpecialPage\SpecialPageFactory->executePath(string, RequestContext)
#16 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(948): MediaWiki->performRequest()
#17 /srv/mediawiki/php-1.41.0-wmf.18/includes/MediaWiki.php(597): MediaWiki->main()
#18 /srv/mediawiki/php-1.41.0-wmf.18/index.php(50): MediaWiki->run()
#19 /srv/mediawiki/php-1.41.0-wmf.18/index.php(46): wfIndexMain()
#20 /srv/mediawiki/w/index.php(3): require(string)
#21 {main}
Impact
Notes

Looks like if gsroffset is not an integer it causes a fatal error

Details

Request URL
https://commons.wikimedia.org/w/index.php?2302=*&30=*&33=*&a=*&all=*&autofocus=*&continue=*&csrf_token=*&fulltext=*&go=*&hasFilters=*&height=*&help=*&imageStyle=*&keyword=*&path=*&redirect=*&results=*&search=*&thumbwidth=*&title=*&token=*&wordcount=*

Event Timeline

When calling a api module from php code the ApiMain class detects this as "internal mode" and does not provide error handling. The execption is thrown and not catched by the api to provide the readable error.

Doing the same api request from a browser it shows as:

{
    "error": {
        "code": "badinteger",
        "info": "Invalid value \"lk2id\" for integer parameter \"gsroffset\".",
        "*": "See https://????/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."
    },
    "servedby": "mw????"
}

Just validate the param in the caller code or catch? -- https://codesearch.wmcloud.org/deployed/?q=catch%5Cs*%5C%28%5Cs*%5C%5C%3FApiUsageException&files=&excludeFiles=tests%2F

matthiasmullie renamed this task from ApiUsageException: Invalid value for integer parameter "gsroffset". to [S] ApiUsageException: Invalid value for integer parameter "gsroffset"..Sep 6 2023, 1:25 PM

Change #1089710 had a related patch set uploaded (by Ammarpad; author: Ammarpad):

[mediawiki/extensions/MediaSearch@master] SpecialMediaSearch: Add error handling for search API errors

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

https://commons.wikimedia.org/wiki/Special:MediaSearch?type=image&search=cat&continue=lk2id is an example that triggers this fatal error (but should be converted into a user-friendlier warning after @Ammarpad's patch ends up deployed)

Change #1089710 merged by jenkins-bot:

[mediawiki/extensions/MediaSearch@master] SpecialMediaSearch: Add error handling for search API errors

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

Etonkovidova subscribed.

For wmf.5 there is only 3 errors reported (one error was triggered by me). The link to check in wmf.6 - https://logstash.wikimedia.org/goto/c9af3ee2d48842d4b52f240e907873fe

Etonkovidova claimed this task.

(the other 2 were me)

Thx, @matthiasmullie :) I re-checked for commons wmf.6 - no errors