Page MenuHomePhabricator

Fix error logging in TranslateRenderJob
Closed, ResolvedPublic2 Estimated Story PointsBUG REPORT

Description

The following code in Translate should be fixed in TranslateRenderJob:

if ( !$editStatus->isOK() ) {
    $this->logError(
        'Error while editing content in page.',
        [
            'content' => $content,
            'errors' => $editStatus->getErrors()
        ]
    );
}

Original report

I have translated 11 strings of total 15 strings of Template:Bundled to Finnish in MediaWiki.org using Translate extension. Page Template:Bundled/fi still doesn't exist, despite the first translations made by me on 5 February. Still it doesn't exist.

Task was created after pointer from Support Desk: https://www.mediawiki.org/wiki/Topic:Wq2bgjich901biap

Event Timeline

Jnovikov renamed this task from MediaWiki.org: Template that have several strings translated with Translate extension didn to MediaWiki.org: Template that have several strings translated with Translate extension doesnt exist.Feb 15 2022, 11:16 AM
Jnovikov updated the task description. (Show Details)
Jnovikov updated the task description. (Show Details)
Nikerabbit subscribed.

I will check logs for any clues.

I edited a Finnish translation. Page is still not created.

Translate logs say the following:

Feb 22, 2022 @ 12:44:03.063	TranslateRenderJob [Template:Bundled/fi]: Finished page edit operation
Feb 22, 2022 @ 12:44:03.063	TranslateRenderJob [Template:Bundled/fi]: Finished TranslateRenderJob
Feb 22, 2022 @ 12:44:02.391	TranslateRenderJob [Template:Bundled/fi]: Starting TranslateRenderJob

So Translate thinks that the page has been edited, but it isn't.

Logs for the request aren't helpful either:

Feb 22, 2022 @ 12:44:03.063	TranslateRenderJob [Template:Bundled/fi]: Finished page edit operation
Feb 22, 2022 @ 12:44:03.063	TranslateRenderJob [Template:Bundled/fi]: Finished TranslateRenderJob
Feb 22, 2022 @ 12:44:02.588	deleteByQuery against [ttmserver] on cluster [production-search-codfw] with task id [impWJf5XR3KjWviWTx8B5w:784489935] completed
Feb 22, 2022 @ 12:44:02.546	deleteByQuery against [ttmserver] on cluster [production-search-codfw] with task id [impWJf5XR3KjWviWTx8B5w:784489935] starting
Feb 22, 2022 @ 12:44:02.428	deleteByQuery against [ttmserver] on cluster [production-search-eqiad] with task id [OzF9aPpmQy6kwNEdq1irrw:5443387285] completed
Feb 22, 2022 @ 12:44:02.391	TranslateRenderJob [Template:Bundled/fi]: Starting TranslateRenderJob
Feb 22, 2022 @ 12:44:02.341	deleteByQuery against [ttmserver] on cluster [production-search-eqiad] with task id [OzF9aPpmQy6kwNEdq1irrw:5443387285] starting
Feb 22, 2022 @ 12:44:01.816	Transaction spent 8ms in writes, under the 3s limit

Command line debugging also seems to indicate success:

nikerabbit@mwmaint1002:~$ mwscript shell.php --wiki=mediawikiwiki
Psy Shell v0.11.1 (PHP 7.2.34-18+0~20210223.60+debian10~1.gbpb21322+wmf5 — cli) by Justin Hileman
>>> $job = TranslateRenderJob::newJob( Title::newFromText( 'Template:Bundled/fi' ) );
=> TranslateRenderJob {#3372
     +command: "TranslateRenderJob",
     +params: [
       "namespace" => 10,
       "title" => "Bundled/fi",
       "requestId" => "261a2965402a3f58dca9e26a",
       "user" => "FuzzyBot",
       "flags" => 16,
       "summary" => "Updating to match new version of source page",
     ],
     +metadata: [],
   }
>>> $job->run();
=> true

With -d 2 option it fails

[debug] Unstubbing $wgLang on call of $wgLang::unstub from ContentHandler->getPageLanguage
Wikimedia\Services\ContainerDisabledException with message 'Container disabled!'

But this might be a different issue since without debugging it returns success.

Testing manually I finally find some clues. Setup:

$title = Title::newFromText( 'Template:Bundled/fi' );
$tpPage = TranslatablePage::getTranslationPageFromTitle( $title );
$user = MediaWiki\Extension\Translate\SystemUsers\FuzzyBot::getUser();
$summary = wfMessage( 'tpt-render-summary' )->inContentLanguage()->text();
$flags = EDIT_FORCE_BOT;
$page = WikiPage::factory( $title );

// @todo FuzzyBot hack
PageTranslationHooks::$allowTargetEdit = true;
$content = $tpPage->getPageContent();
$editStatus = $page->doUserEditContent( $content, $user, $summary, $flags );

The actual issue:

>>> $editStatus->getValue()
=> []
>>> $editStatus->isGood()
=> false
>>> $editStatus->isOk()
=> false
>>> $editStatus->getErrors()
=> [
     [
       "type" => "error",
       "message" => "templatedata-invalid-parse",
       "params" => [],
     ],
   ]

The code is supposed to log errors:

if ( !$editStatus->isOK() ) {
    $this->logError(
        'Error while editing content in page.',
        [
            'content' => $content,
            'errors' => $editStatus->getErrors()
        ]
    );
}

But I think it silently fails because we pass non-primitives in the context.

Back to the issue. This is what it is trying to save:

<templatedata>\n
   {\n
   \t"params": {\n
   \t\t"1": {\n
   \t\t\t"description": "Versio, jossa tämä laajennus ensimmäisen kerran paketoitiin",\n
   \t\t\t"example": "1.28",\n
   \t\t\t"type": "number",\n
   \t\t\t"autovalue": "{{MW stable branch number}}",\n
   \t\t\t"suggested": true\n
   \t\t},\n
   \t\t"type": {\n
   \t\t\t"description": "Onko paketoitu laajennus ulkoasu vai ei",\n
   \t\t\t"type": "content",\n
   \t\t\t"default": "extension",\n
   \t\t\t"autovalue": "extension",\n
   \t\t\t"example": "skin"\n
   \t\t}\n
   \t},\n
   \t"description": "<span lang="en" dir="ltr" class="mw-content-ltr">This template shows a notice that the extension or skin, on whose page this template is placed, is bundled with a certain version of MediaWiki.</span>"\n
   }\n
   </templatedata>\n

This should really use <translate nowrap> to prevent wrapping that has ", but it still isn't safe because translations might include " in themselves. It's just not safe to use translate tags inside JSON.

Summary

Issue 1: <translate> tags used inside JSON. At least use <translate nowrap> or preferably do not do it this way at all. For MediaWiki translation admins to fix.

Issue 2: The error is not logged. For Translate extension developers to fix by only logging primitive values.

Issue 3: The logging framework does not log about not being able to log. For team responsible of logging, add validation with logging or exceptions.

Thanks for debugging the issue! Indeed, translation tags shouldn't be used on templatedata. In fact, templatedata already supports multiple languages.

I've added all the existing translations to templatedata directly. I haven't marked the page for translation yet in case someone wants to double-check (since marking for translation would delete the units). But otherwise it should fix the problem once it gets marked for translation.

Issue 3 is reported as T302406: MediaWiki logger silently loses invalid log messages. Limiting this task to only for issue 2, which will be prioritized separately.

Nikerabbit renamed this task from MediaWiki.org: Template that have several strings translated with Translate extension doesnt exist to Fix error logging in TranslateRenderJob.Feb 23 2022, 2:51 PM
Nikerabbit updated the task description. (Show Details)

Change 766178 had a related patch set uploaded (by Abijeet Patro; author: Abijeet Patro):

[mediawiki/extensions/Translate@master] TranslateRenderJob: Fix logging when article editing error occurs

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

abi_ changed the task status from Open to In Progress.Feb 25 2022, 6:16 PM
abi_ claimed this task.
abi_ triaged this task as High priority.
abi_ subscribed.

I'm marking this as high priority since this hinders our ability to identify and debug issues. I've also gone ahead and submitted a patch to fix this issue.

Nikerabbit set the point value for this task to 2.Mar 1 2022, 8:16 AM

Change 766178 merged by jenkins-bot:

[mediawiki/extensions/Translate@master] TranslateRenderJob: Fix logging when article editing error occurs

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

For testing, it's sufficient to check the Translate.Jobs channel for error level and see if there are entries. If there are no entries, we may need to manually produce a test case that surely produces a log to confirm.

I can confirm that we see log messages with summary of the content now in Logstash.