Page MenuHomePhabricator

"Import failed: Expected <mediawiki> tag, got " error message isn't helpful to know if entire message was output
Open, LowPublic

Description

Testing another issue, by uploading an invalid XML file I got an error of Import failed: Expected <mediawiki> tag, got script.

It wasn't obvious that the error message was all there due to a lack of any trailing punctuation or similar.

See also: T259527: Special:Import failed at Wikispecies: "Import failed: Expected <mediawiki> tag, got", which highlights the error too (though, is presumably about the import actually failing, and the lack of anything identified).

			if ( $this->reader->localName != 'mediawiki' ) {
				// phpcs:ignore Generic.PHP.NoSilencedErrors
				@libxml_disable_entity_loader( $oldDisable );
				$error = libxml_get_last_error();
				if ( $error ) {
					throw new NormalizedException( "XML error at line {line}: {message}", [
						'line' => $error->line,
						'message' => $error->message,
					] );
				} else {
					throw new MWException( "Expected <mediawiki> tag, got " .
						$this->reader->localName );
				}
			}

https://www.php.net/manual/en/class.xmlreader.php#xmlreader.props.localname

Something like Import failed: Expected '<mediawiki>' tag, got '<{$this->reader->localName}>' tag. would be better than what is there now. tag/node/element work too.

Then in practice, we'd get Import failed: Expected '<mediawiki>' tag, got '<script>' tag.

Looks like XML error at line {line}: {message} could be similarly confusing from a lack of termination.

Event Timeline

Reedy renamed this task from "Import failed: Expected <mediawiki> tag, got " error message isn't helpful to "Import failed: Expected <mediawiki> tag, got " error message isn't helpful to know if it was all output.Jul 9 2023, 10:29 PM
Reedy triaged this task as Low priority.
Reedy updated the task description. (Show Details)
Reedy updated the task description. (Show Details)
Reedy renamed this task from "Import failed: Expected <mediawiki> tag, got " error message isn't helpful to know if it was all output to "Import failed: Expected <mediawiki> tag, got " error message isn't helpful to know if entire message was output.Jul 9 2023, 10:44 PM
Reedy updated the task description. (Show Details)

Change 936123 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@master] WikiImporter: Improve error message output

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

Change 936123 merged by jenkins-bot:

[mediawiki/core@master] WikiImporter: Improve error message output

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

Change 936728 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_40] WikiImporter: Improve error message output

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

Change 936729 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_39] WikiImporter: Improve error message output

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

Change 936730 had a related patch set uploaded (by Reedy; author: Reedy):

[mediawiki/core@REL1_35] WikiImporter: Improve error message output

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

Change 936730 merged by jenkins-bot:

[mediawiki/core@REL1_35] WikiImporter: Improve error message output

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

Change 936729 merged by jenkins-bot:

[mediawiki/core@REL1_39] WikiImporter: Improve error message output

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

Change 936728 merged by jenkins-bot:

[mediawiki/core@REL1_40] WikiImporter: Improve error message output

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