I accidentally made the following API request:
https://www.wikidata.org/w/api.php?action=wbformatvalue&generate=text%2Fhtml&datavalue=%7B%22type%22%3A%22wikibase-entityid%22%2C%20%22value%22%3A%20%7B%22id%22%3A%22L10-F3%22%7D%7D&datatype=wikibase-lexeme == https://www.wikidata.org/w/api.php?action=wbformatvalue&generate=text/html&datavalue={"type":"wikibase-entityid", "value": {"id":"L10-F3"}}&datatype=wikibase-lexeme
i. e., attempting to format a form ID value ({"type":"wikibase-entityid", "value": {"id":"L10-F3"}}) as a lexeme datatype.
It results in the following log error:
InvalidArgumentException: Not a lexeme ID: L10-F3 /srv/mediawiki/php-1.32.0-wmf.26/extensions/WikibaseLexeme/src/Formatters/LexemeIdHtmlFormatter.php:58 #0 /srv/mediawiki/php-1.32.0-wmf.26/extensions/Wikibase/lib/includes/Formatters/EntityIdValueFormatter.php(44): Wikibase\Lexeme\Formatters\LexemeIdHtmlFormatter->formatEntityId(Wikibase\Lexeme\DataModel\FormId) #1 /srv/mediawiki/php-1.32.0-wmf.26/extensions/Wikibase/lib/includes/Formatters/DispatchingValueFormatter.php(75): Wikibase\Lib\EntityIdValueFormatter->format(Wikibase\DataModel\Entity\EntityIdValue) #2 /srv/mediawiki/php-1.32.0-wmf.26/extensions/Wikibase/repo/includes/Api/FormatSnakValue.php(104): Wikibase\Lib\Formatters\DispatchingValueFormatter->formatValue(Wikibase\DataModel\Entity\EntityIdValue, string) #3 /srv/mediawiki/php-1.32.0-wmf.26/includes/api/ApiMain.php(1570): Wikibase\Repo\Api\FormatSnakValue->execute() #4 /srv/mediawiki/php-1.32.0-wmf.26/includes/api/ApiMain.php(531): ApiMain->executeAction() #5 /srv/mediawiki/php-1.32.0-wmf.26/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling() #6 /srv/mediawiki/php-1.32.0-wmf.26/api.php(87): ApiMain->execute() #7 /srv/mediawiki/w/api.php(3): include(string) #8 {main}
The Plan (extracted from a comment below)
From the investigation (T209368) we want to do the following
1 - ValueFormatter interface (datavalues/interfaces) - https://github.com/DataValues/Interfaces/pull/44
The ValueFormatter interface should be documented as allowing InvalidArgumentExceptions to be thrown when arguments are known to be wrong for the type of Formatter instance.
Many instances of ValueFormatter already do this, but lets add it to the interface documentation.
2 - EntityIdFormatter interface (datamodel-services) - https://github.com/wmde/WikibaseDataModelServices/pull/213
EntityIdFormatter interface should also document throwing an InvalidArgumentException when being provided with an argument that the current formatter can not format.
3 - FormatSnakValue API
EntityIdValueFormatter::format itself already throws InvalidArgumentExceptions, and the 2 cases above bubble up through this method.
When $valueFormatter->format is called in the FormatSnakValue API, InvalidArgumentExceptions from the call should be caught and exposed to the user as a regular API error, not an exception.