Page MenuHomePhabricator

"PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue [Story Points 5]
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

MediaWiki version: 1.35.0-wmf.4

message
[{exception_id}] {exception_url}   ErrorException from line 184 of /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/DmsCoordinateParser.php: PHP Notice: A non well formed numeric value encountered
exception.trace
#0 /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/DmsCoordinateParser.php(184): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/DdCoordinateParser.php(47): DataValues\Geo\Parsers\DmsCoordinateParser->parseCoordinate(string)
#2 /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/LatLongParserBase.php(106): DataValues\Geo\Parsers\DdCoordinateParser->getParsedCoordinate(string)
#3 /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/DdCoordinateParser.php(114): DataValues\Geo\Parsers\LatLongParserBase->parse(string)
#4 /srv/mediawiki/php-1.35.0-wmf.4/vendor/data-values/geo/src/Parsers/GlobeCoordinateParser.php(54): DataValues\Geo\Parsers\DdCoordinateParser->parse(string)
#5 /srv/mediawiki/php-1.35.0-wmf.4/extensions/Wikibase/repo/includes/Api/ParseValue.php(198): DataValues\Geo\Parsers\GlobeCoordinateParser->parse(string)
#6 /srv/mediawiki/php-1.35.0-wmf.4/extensions/Wikibase/repo/includes/Api/ParseValue.php(110): Wikibase\Repo\Api\ParseValue->parseStringValue(DataValues\Geo\Parsers\GlobeCoordinateParser, string, NULL)
#7 /srv/mediawiki/php-1.35.0-wmf.4/includes/api/ApiMain.php(1603): Wikibase\Repo\Api\ParseValue->execute()
#8 /srv/mediawiki/php-1.35.0-wmf.4/includes/api/ApiMain.php(539): ApiMain->executeAction()
#9 /srv/mediawiki/php-1.35.0-wmf.4/includes/api/ApiMain.php(510): ApiMain->executeActionWithErrorHandling()
#10 /srv/mediawiki/php-1.35.0-wmf.4/api.php(83): ApiMain->execute()
#11 /srv/mediawiki/w/api.php(3): require(string)
#12 {main}

Impact

Unclear.

A couple of instances since rolling wmf.4 to all wikis:

brennen@mwlog1001:/srv/mw-log$ grep -c vendor/data-values/geo/src/Parsers/DmsCoordinateParser.php:184 ./error.log
2

Notes

I'm not finding anything earlier than wmf.4 for this, though the error message is similar to T231551 and T226751.

Full URL linked in this phab ticket is https://www.wikidata.org/w/api.php?action=wbparsevalue&format=json&parser=globecoordinate&values=%1F33%C2%B007%2723%22S%2C%2064%C2%B02%2E10%22E&options=%7B%22lang%22%3A%22en%22%2C%22precision%22%3A2%2E77778e-7%7D

Details

Request ID
XbtjRgpAAEcAAIWyZ6oAAADK
Request URL
/w/api.php?action=wbparsevalue&format=json&parser=globecoordinate&values=…

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle renamed this task from DmsCoordinateParser: PHP Notice: A non well formed numeric value encountered to "PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue.Nov 7 2019, 9:04 PM
Krinkle changed Request URL from /w/api.php?action=wbparsevalue&format=json&parser=globecoordinate&values=%1F33%C2%B007%2723%22S%2C%2064%C2%B02%2E10%22E&options=%7B%22lang%22%3A%22en%22%2C%22precision%22%3A2%2E77778e-7%7D to /w/api.php?action=wbparsevalue&format=json&parser=globecoordinate&values=….
Krinkle updated the task description. (Show Details)
Krinkle edited Stack Trace. (Show Details)
Krinkle updated the task description. (Show Details)
Krinkle added a subscriber: Krinkle.

Re-classifying from mediawiki-extensions-GeoData to mediawiki-extensions-WikibaseRepo. While it contains "Geo"-something, this specific error comes from the Wikibase code.

Addshore moved this task from Incoming to Ready to estimate on the Wikidata-Campsite board.

Check if the issue still happening after T238931 is addressed.

So, it looks like an exception is being caught, and dismissed, but still being logged.
The desired behaviour here would be that no log occurs for this.

Addshore renamed this task from "PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue to "PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue [5 Point Value].Dec 10 2019, 1:11 PM
Addshore renamed this task from "PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue [5 Point Value] to "PHP Notice: A non well formed numeric value encountered" from DmsCoordinateParser.php in API action=wbparsevalue [Story Points 5].Dec 10 2019, 2:11 PM

So, it looks like an exception is being caught, and dismissed, but still being logged.
The desired behaviour here would be that no log occurs for this.

I couldn't find any obvious place that logs the error...

In case there is confusion - the error reported in this case is logged by the PHP engine, not by our code.

It comes from the following statement:

Source: DmsCoordinateParser.php:L184

DmsCoordinateParser
( $minutePosition === false ? $degreePosition : $minutePosition ) + 1,

It means one of these two variables (not sure which) is not actually numerical.

Minimal example case: https://3v4l.org/qkvjm.

If nothing major is broken right now as far as we can tell, I would suggest adding a conditional for is_numeric or some such, and when not-numerical use an explicit fallback of 0 (this is what PHP is doing today already). Perhaps also use the condition to make a custom log message to an Wikibase-injected log channel with additional details, so that in the future the condition can have a code comment that explains when and why this is okay to happen (or if we find otherwise, fix it at the source and then then turn the condition into a fatal exception, for example).

The same might be easier at a higher layer (eg. Wikibase/Api/ParseValue) if the bad input is detectable from there even, I don't know.

Thanks @Krinkle for the hint, it was super helpful.

The important thing is that the value that causes this problem is actually a valid value: 33°07'23"S, 64°2.10"E"

After putting var_dump in line 184 of the file. It turned out that the problem is when php tries to sum a string and a float.

array(3) { [0]=> float(33) [1]=> string(2) "07" [2]=> string(2) "23" }

This is fixed in the new version of geo so simply upgrading geo would fix it but upgrading the library causes errors in other places: T238931: Wikibase lib with datavalues/geo 4.2.0 has a test failure

Given that it'll be automatically fixed by the upgrade, I move this to freezer until we upgrade geo.