Page MenuHomePhabricator

Undefined index: june in DateFormatter.php (makeIsoMonth)
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error

Request URL: /w/api.php
Request ID: XK0fgwpAAEgAACcCMawAAABO

message
PHP Notice: Undefined index: june
trace
#0 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/DateFormatter.php(351): MWExceptionHandler::handleError(integer, string, string, integer, array, array)
#1 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/DateFormatter.php(260): DateFormatter->makeIsoMonth(string)
#2 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/DateFormatter.php(227): DateFormatter->formatDate(array, string, boolean)
#3 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/DateFormatter.php(202): DateFormatter->replace(array)
#4 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/CoreParserFunctions.php(128): DateFormatter->reformat(integer, string, array)
#5 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3510): CoreParserFunctions::formatDate(Parser, string, string)
#6 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3217): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#7 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#8 /srv/mediawiki/php-1.33.0-wmf.24/extensions/ParserFunctions/includes/ExtParserFunctions.php(106): PPFrame_Hash->expand(PPNode_Hash_Tree)
#9 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3510): ExtParserFunctions::ifObj(Parser, PPTemplateFrame_Hash, array)
#10 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3217): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#11 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#12 /srv/mediawiki/php-1.33.0-wmf.24/extensions/ParserFunctions/includes/ExtParserFunctions.php(108): PPFrame_Hash->expand(PPNode_Hash_Tree)
#13 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3510): ExtParserFunctions::ifObj(Parser, PPTemplateFrame_Hash, array)
#14 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3217): Parser->callParserFunction(PPTemplateFrame_Hash, string, array)
#15 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPTemplateFrame_Hash)
#16 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3391): PPFrame_Hash->expand(PPNode_Hash_Tree)
#17 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Preprocessor_Hash.php(1114): Parser->braceSubstitution(array, PPFrame_Hash)
#18 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(3031): PPFrame_Hash->expand(PPNode_Hash_Tree, integer)
#19 /srv/mediawiki/php-1.33.0-wmf.24/includes/parser/Parser.php(740): Parser->replaceVariables(string, PPFrame_Hash)
#20 /srv/mediawiki/php-1.33.0-wmf.24/extensions/ParsoidBatchAPI/includes/ApiParsoidBatch.php(222): Parser->preprocess(string, Title, ParserOptions, integer)
#21 /srv/mediawiki/php-1.33.0-wmf.24/extensions/ParsoidBatchAPI/includes/ApiParsoidBatch.php(118): ApiParsoidBatch->preprocess(string, Title, integer)
#22 /srv/mediawiki/php-1.33.0-wmf.24/includes/api/ApiMain.php(1595): ApiParsoidBatch->execute()
#23 /srv/mediawiki/php-1.33.0-wmf.24/includes/api/ApiMain.php(531): ApiMain->executeAction()
#24 /srv/mediawiki/php-1.33.0-wmf.24/includes/api/ApiMain.php(502): ApiMain->executeActionWithErrorHandling()
#25 /srv/mediawiki/php-1.33.0-wmf.24/api.php(87): ApiMain->execute()
#26 /srv/mediawiki/w/api.php(3): include(string)
#27 {main}

Impact

Such logspam! So error!

Notes

176 occurrences in the past 1 hour.

Event Timeline

Krinkle triaged this task as Unbreak Now! priority.Apr 9 2019, 11:33 PM
Krinkle added subscribers: MaxSem, Krinkle.

From the stack trace…

The error is discovered at this line of code:

	private function makeIsoMonth( $monthName ) {
		$n = $this->xMonths[$this->lang->lc( $monthName )];
		return sprintf( '%02d', $n );
	}

This suggests something might be wrong with the populating of the xMonths array. I don't see anything obvious stand out, but my best guess is that somehow the refactoring in ParserExtensions may have caused some assumption about which Language is used, to no longer be true, and thus it can no longer find the month names.

It's probably just a change in the input text, not a change in the code. DateFormatter.php is obviously broken, line 260 calls makeIsoMonth() speculatively, and checks if the return value is false or "00", anticipating this error but not the notice that goes with it. $fail is set to true, but $bits['m'] is subsequently used anyway, even though it is unset. It's used to construct text that is subsequently thrown away at line 314, and then used again unconditionally at line 321.

The only ParserFunctions changes in wmf.24 are unit test refactoring and PHP entry point removal, so unrelated.

A significant amount of DateFormatter.php is unchanged since I introduced it in November 2003, including makeIsoMonth() and the check of its return value. It was one of the first things I wrote in PHP. I was developing with PHP notices disabled at the time. Code was often committed that emitted notices, we just had them disabled in production. It took a while for us to make it a development policy to not emit notices.

The notice on line 351 does indeed appear to be the fault of this code I wrote in 2003, so if this bug was a person, its voice would have broken by now. The notice from line 321 which I see is also in the logs appears to date from 2009.

The months are combined into a regex without preg_quote(), which wasn't quite so bad in the original commit, which only supported English and thus fairly well-known and well-behaved month names. Now that other language are supported, it becomes a problem, since for example German has "jun" => "Jun.". So the bug can be reproduced with:

$opts = new ParserOptions;
$opts->setTargetLanguage( Language::factory('de'));
print $wgParser->parse('{{#dateformat:4 june}}', Title::newMainPage(), $opts)->getText();

The input "june" matches /Jun./i but it is not in xMonths, so a notice results.

Change 502670 had a related patch set uploaded (by Tim Starling; owner: Tim Starling):
[mediawiki/core@master] Fix notices emitted from DateFormatter

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

Change 502670 merged by jenkins-bot:
[mediawiki/core@master] Fix notices emitted from DateFormatter

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

Change 502819 had a related patch set uploaded (by Krinkle; owner: Tim Starling):
[mediawiki/core@wmf/1.33.0-wmf.25] Fix notices emitted from DateFormatter

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

Krinkle assigned this task to tstarling.

Change 502819 merged by jenkins-bot:
[mediawiki/core@wmf/1.33.0-wmf.25] Fix notices emitted from DateFormatter

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

Mentioned in SAL (#wikimedia-operations) [2019-04-10T15:46:01Z] <krinkle@deploy1001> Synchronized php-1.33.0-wmf.25/includes/parser/DateFormatter.php: Ib2b3fb315dc93b / T220563 (duration: 01m 00s)

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