Page MenuHomePhabricator

PHP Warning: count(): Parameter must be an array or an object that implements Countable
Closed, ResolvedPublic

Description

Error

Request ID: AWmcomha8aQffZ3H9FZs

message
PHP Warning: count(): Parameter must be an array or an object that implements Countable
trace
#0 /srv/mediawiki/php-1.33.0-wmf.22/includes/parser/BlockLevelPass.php(202): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.33.0-wmf.22/includes/parser/BlockLevelPass.php(52): BlockLevelPass->execute()
#2 /srv/mediawiki/php-1.33.0-wmf.22/includes/parser/Parser.php(2555): BlockLevelPass::doBlockLevels(string, boolean)
#3 /srv/mediawiki/php-1.33.0-wmf.22/includes/parser/Parser.php(1415): Parser->doBlockLevels(string, boolean)
#4 /srv/mediawiki/php-1.33.0-wmf.22/includes/parser/Parser.php(485): Parser->internalParseHalfParsed(string, boolean, boolean)
#5 /srv/mediawiki/php-1.33.0-wmf.22/includes/cache/MessageCache.php(1260): Parser->parse(string, Title, ParserOptions, boolean)
#6 /srv/mediawiki/php-1.33.0-wmf.22/includes/Message.php(1265): MessageCache->parse(string, Title, boolean, boolean, LanguageEn)
#7 /srv/mediawiki/php-1.33.0-wmf.22/includes/Message.php(890): Message->parseText(string)
#8 /srv/mediawiki/php-1.33.0-wmf.22/includes/Message.php(943): Message->toString(string)
#9 /srv/mediawiki/php-1.33.0-wmf.22/includes/EditPage.php(3614): Message->parse()
#10 /srv/mediawiki/php-1.33.0-wmf.22/includes/EditPage.php(2980): EditPage->showEditTools()
#11 /srv/mediawiki/php-1.33.0-wmf.22/includes/EditPage.php(719): EditPage->showEditForm()
#12 /srv/mediawiki/php-1.33.0-wmf.22/includes/actions/EditAction.php(60): EditPage->edit()
#13 /srv/mediawiki/php-1.33.0-wmf.22/includes/MediaWiki.php(501): EditAction->show()
#14 /srv/mediawiki/php-1.33.0-wmf.22/includes/MediaWiki.php(294): MediaWiki->performAction(Article, Title)
#15 /srv/mediawiki/php-1.33.0-wmf.22/includes/MediaWiki.php(867): MediaWiki->performRequest()
#16 /srv/mediawiki/php-1.33.0-wmf.22/includes/MediaWiki.php(517): MediaWiki->main()
#17 /srv/mediawiki/php-1.33.0-wmf.22/index.php(42): MediaWiki->run()
#18 /srv/mediawiki/w/index.php(3): require(string)
#19 {main}

Impact

Notes

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMar 20 2019, 8:05 PM
zeljkofilipin triaged this task as Unbreak Now! priority.Mar 20 2019, 8:05 PM
Restricted Application added subscribers: Liuxinyu970226, TerraCodes. · View Herald TranscriptMar 20 2019, 8:05 PM

@zeljkofilipin Looking, thanks. Maybe it should be an iterator_count ...

Change 497862 had a related patch set uploaded (by D3r1ck01; owner: Derick Alangi):
[mediawiki/core@master] parser: Check that $textLines is an array that can be iterated

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

Change 497863 had a related patch set uploaded (by Arlolra; owner: Arlolra):
[mediawiki/core@master] Count occurrences of newlines

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

Change 497862 abandoned by D3r1ck01:
parser: Check that $textLines is an array that can be iterated

Reason:
superseded by https://gerrit.wikimedia.org/r/#/c/497863/

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

Change 497865 had a related patch set uploaded (by C. Scott Ananian; owner: C. Scott Ananian):
[mediawiki/core@master] Don't count the input lines

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

Change 497863 merged by jenkins-bot:
[mediawiki/core@master] parser: Count occurrences of newlines

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

Hold up, there's another bug here with ExplodeIterator we're discussing.

cscott added a comment.EditedMar 20 2019, 9:02 PM

ExplodeIterator::key() returns $this->curPos, *not* the line number. So with the 497863 patch it fixes the exceptions (and so should be fine to backport to wmf.22) but for wikitexts over a thousand lines it will effectively "never always be on the last line" and so you'll get an extra trailing newline.

I think that's harmless for wmf.22, but we'll probably want to amend the patch; either 497865 or else just moving $i=0 outside the loop and $i++ inside the loop so we're always counting lines (EDIT: that's 497871).

EDIT: oops, got the sense of the test wrong, since there's a less-than comparison, not a simple equals. So this is more significant that I'd thought.

Change 497871 had a related patch set uploaded (by Arlolra; owner: Arlolra):
[mediawiki/core@master] parser: More accounting for ExplodeIterator

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

Change 497879 had a related patch set uploaded (by C. Scott Ananian; owner: Arlolra):
[mediawiki/core@master] BlockLevelPass: further fixes for T218817

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

Change 497871 had a related patch set uploaded (by Arlolra; owner: Arlolra):
[mediawiki/core@master] BlockLevelPass: further fixes for T218817

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

Change 497879 abandoned by Arlolra:
BlockLevelPass: further fixes for T218817

Reason:
As PS4 on https://gerrit.wikimedia.org/r/c/mediawiki/core/ /497871

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

Change 497871 merged by jenkins-bot:
[mediawiki/core@master] BlockLevelPass: further fixes for T218817

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

Change 497865 merged by jenkins-bot:
[mediawiki/core@master] Avoid counting input lines twice in BlockLevelPass::execute()

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

Which of the patches should get back-ported?

The final result, I41a45266d266195aa6002d3854e018cacf052ca6, is the one we want but since they all stack on top of each other, you might have to do all three. It's fine to just rebase the last one though.

Change 497939 had a related patch set uploaded (by Jforrester; owner: Arlolra):
[mediawiki/core@wmf/1.33.0-wmf.22] parser: Count occurrences of newlines

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

Change 497940 had a related patch set uploaded (by Jforrester; owner: Arlolra):
[mediawiki/core@wmf/1.33.0-wmf.22] BlockLevelPass: further fixes for T218817

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

Change 497941 had a related patch set uploaded (by Jforrester; owner: C. Scott Ananian):
[mediawiki/core@wmf/1.33.0-wmf.22] Avoid counting input lines twice in BlockLevelPass::execute()

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

Change 497939 merged by jenkins-bot:
[mediawiki/core@wmf/1.33.0-wmf.22] parser: Count occurrences of newlines

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

Change 497940 merged by jenkins-bot:
[mediawiki/core@wmf/1.33.0-wmf.22] BlockLevelPass: further fixes for T218817

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

Change 497941 merged by jenkins-bot:
[mediawiki/core@wmf/1.33.0-wmf.22] Avoid counting input lines twice in BlockLevelPass::execute()

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

It would be a good idea to add some parser tests which exercise both modes of StringUtils::explode. If this hadn't thrown an exception for being not Countable, we probably wouldn't have noticed that the array keys shift on large articles until it made production.

Arlolra closed this task as Resolved.Mar 21 2019, 1:07 AM
Arlolra claimed this task.

It would be a good idea to add some parser tests which exercise both modes of StringUtils::explode

I've already filed T218834 for that.

Probably fixed?

I think so.

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