Page MenuHomePhabricator

PHP Warning: Illegal string offset 'lang' from ApiVisualEditor.php
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

Request ID: XIxtJApAEDIAAE3EcFsAAAAG

message
PHP Warning: Illegal string offset 'lang'
trace
#1 /srv/mediawiki/php-1.33.0-wmf.21/extensions/VisualEditor/includes/ApiVisualEditor.php(664): ApiVisualEditor->getLangLinks(Title)
#2 /srv/mediawiki/php-1.33.0-wmf.21/includes/api/ApiMain.php(1595): ApiVisualEditor->execute()
#3 /srv/mediawiki/php-1.33.0-wmf.21/includes/api/ApiMain.php(531): ApiMain->executeAction()
#4 /srv/mediawiki/php-1.33.0-wmf.21/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#5 /srv/mediawiki/php-1.33.0-wmf.21/api.php(87): ApiMain->execute()
#6 /srv/mediawiki/w/api.php(3): require(string)

Impact

Unknown.

Due to the error being non-fatal, the program unfortunately continues with unspecified behaviour. I do not know what the accidental outcome is and whether it happens to be correct, or whether it corrupts something on pages.

Notes

Seen about 700 times in the past week under Logstash/mediawiki-errors from PHP 7 beta testers.

The error is likely many times more frequent than that for all other users. However, HHVM does not have detection for this error. Instead, it casts the string 'lang' to the number 0 and returns the first character of the string that the code is performing ['lang'] on. This is most certainly not the intended behaviour.

Event Timeline

matmarex edited projects, added VisualEditor (Current work); removed VisualEditor.
matmarex subscribed.

Hold on, I remember this bug:

I think we're seeing the internal properties the API uses to nicely format JSON or XML output. You can see them in the web API with format=rawfm: https://en.wikipedia.beta.wmflabs.org/w/api.php?action=query&prop=revisions&format=json&rvprop=timestamp|user|parsedcomment|ids&rvlimit=25&pageids=7776&format=rawfm – note the "_element": "rev" (I think this is what we get in the foreach() loop) and other properties prefixed with _.

Looks like we can ask the API to strip these for us by calling ->getResultData( null, [ 'Strip' => 'all' ] ) instead of just ->getResultData().

Apparently, the 'Illegal string offset' warning is not emitted by HHVM, so we're not running into this at WMF: https://3v4l.org/YU0dV

On second thought, we use the result in our own output, so maybe stripping the metadata is not ideal. I'm actually not sure whether it's important in this particular case. So let's just add an is_array() check like in the other task.

Change 497362 had a related patch set uploaded (by Bartosz Dziewoński; owner: Bartosz Dziewoński):
[mediawiki/extensions/VisualEditor@master] ApiVisualEditor: Fix PHP warning caused by unexpected API metadata

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

Change 497362 merged by jenkins-bot:
[mediawiki/extensions/VisualEditor@master] ApiVisualEditor: Fix PHP warning caused by unexpected API metadata

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

Jdforrester-WMF subscribed.

Last new occurrence in prod was 2019-03-21T12:26:24. Declaring this Resolved. Thank you!

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