Page MenuHomePhabricator

Importing an invalid gettext file causes "Fatal exception of type MWException"
Closed, ResolvedPublicPRODUCTION ERROR

Description

Steps to reproduce:

This results in an internal error page: "Fatal exception of type MWException"

Instead, the user should receive a proper error message, if possible with more detail about the invalid parts. The corresponding internal error on testwiki at least tells the user that file lacks a valid header:

This results in the following error message:

Internal error - Test {{SITENAME}}
[609c3d98] /wiki/Special:ImportTranslations Exception from line 107 of /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php: Gettext file header was not found:

test
Backtrace:
#0 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php(67): GettextFFS::parseGettextData(string, boolean, StringMatcher, string)
#1 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/ffs/GettextFFS.php(47): GettextFFS->parseGettext(string)
#2 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/specials/SpecialImportTranslations.php(196): GettextFFS->readFromVariable(string)
#3 /usr/local/apache/common-local/php-1.23wmf5/extensions/Translate/specials/SpecialImportTranslations.php(70): SpecialImportTranslations->parseFile(string)
#4 /usr/local/apache/common-local/php-1.23wmf5/includes/SpecialPage.php(670): SpecialImportTranslations->execute(NULL)
#5 /usr/local/apache/common-local/php-1.23wmf5/includes/SpecialPageFactory.php(488): SpecialPage->run(NULL)
#6 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(298): SpecialPageFactory::executePath(Title, RequestContext)
#7 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(596): MediaWiki->performRequest()
#8 /usr/local/apache/common-local/php-1.23wmf5/includes/Wiki.php(460): MediaWiki->main()
#9 /usr/local/apache/common-local/php-1.23wmf5/index.php(49): MediaWiki->run()
#10 /usr/local/apache/common-local/w/index.php(3): require(string)
#11 {main}


Version: unspecified
Severity: minor
See Also:
T42341: Enable translation import on wikis with Translate extension

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 2:16 AM
bzimport set Reference to bz57964.
bzimport added a subscriber: Unknown Object (MLST).

ntekriwal wrote:

Removed else throw MWexception line -111

The fatal exception is being thrown because in /Translate/ffs/GettextFFS.php its defined
if ( $match !== null ) {

			$headerBlock = self::formatForWiki( $match, 'trim' );
			$headers = self::parseHeaderTags( $headerBlock );

			// Check for pot-mode by checking if the header is fuzzy
			$flags = self::parseFlags( $headerSection );
			if ( in_array( 'fuzzy', $flags, true ) ) {
				$potmode = true;
			}
		} else {
			throw new MWException( "Gettext file header was not found:\n\n$data" );
		}

This overwrites the checkError call in SpecialImportTransaltions.php

protected function checkError( $msg ) {

		// Give grep a chance to find the usages:
		// translate-import-err-dl-failed, translate-import-err-ul-failed,
		// translate-import-err-invalid-title, translate-import-err-no-such-file,
		// translate-import-err-stale-group, translate-import-err-no-headers,
		// translate-import-err-warnings
		if ( $msg[0] !== 'ok' ) {
			$errorWrap = "<div class='error'>\n$1\n</div>";
         
			$msg[0] = 'translate-import-err-' . $msg[0];

			$this->getOutput()->wrapWikiMsg( $errorWrap, $msg );
			$this->outputForm();

			return true;
		}

		return false;

}

Remove the else statement in
public static function parseGettextData( $data, $useCtxtAsKey, $mangler, $keyAlgorithm )
GettextFFS.php

I have attached the correct file.

Attached:

(In reply to ntekriwal from comment #1)

I have attached the correct file.

Thank you! Can you submit the patch in gerrit next time? See instructions at https://www.mediawiki.org/wiki/Git/Tutorial or do it via web with the https://www.mediawiki.org/wiki/Gerrit_patch_uploader

With your patch, did you verify that the output is a "translate-import-err-no-headers" error? Removing the exception is an improvement only if we actually give useful information to the user as requested in comment 0. :)

ntekriwal wrote:

Yes I verified $msg[0] gets "no headers"
And the error shown is :
"File is not a well formed Gettext file in Translate extension format: Unable to determine message group and language from file headers."

So we need a patch in Gerrit, to review it there. Would you be interested in trying that? :)

Change 166187 had a related patch set uploaded by Brainzest:
Fix for bug 57964

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

Change 166187 abandoned by Brainzest:
Fix for bug 57964

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

Change 166391 had a related patch set uploaded by Brainzest:
Fix for bug 57964

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

Change 166391 abandoned by Siebrand:
Fix for bug 57964

Reason:
I'm abandoning this. This should be mitigated in the caller.

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

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

Change 639877 had a related patch set uploaded (by Mholloway; owner: Michael Holloway):
[mediawiki/extensions/Translate@master] Catch exception and show appropriate UI message on bad file upload

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

Change 639877 merged by jenkins-bot:
[mediawiki/extensions/Translate@master] Catch exception and show appropriate UI message on bad file upload

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

Mholloway claimed this task.
Mholloway subscribed.

Verified the fix on Beta testwiki.