Page MenuHomePhabricator

Adaptation fails for inline images without caption
Closed, ResolvedPublic

Description

After this patch, we have:

let sourceImage, textChunks;

textChunks = this.isInlineImage ? [] : this.node.children.textChunks;
for ( let i = 0, len = textChunks.length; i < len; i++ ) {
    // <some logic to set sourceImage variable>
}

if ( this.isInlineImage && this.node.attributes[ 'data-mw' ] ) {
    // <parts of code where sourceImage isn't assigned to>
    return this.node;
}

if ( !sourceImage ) {
     throw new Error( 'img tag not found in the figure with mw:Image/Thumb for id: ' + this.node.attributes.id );
}

From the above, if this.isInlineImage is true, textChunks will be empty array, thus for loop won't do anything. sourceImage remains undefined in that scenario.

If condition if ( this.isInlineImage && this.node.attributes[ 'data-mw' ] ) does not pass, like in case of inline images with no caption, we will definitely have an error thrown.

This was found while trying to reproduce T199308. There is one example how to reproduce this ("Uma Thurman" from English to Spanish).

Event Timeline

Are you sure about this? There is a return statement in the condition above.

	if ( this.isInlineImage && this.node.attributes[ 'data-mw' ] ) {
	    ...
	   return this.node;  // <--- Note this
	}

	if ( !sourceImage ) {
		throw new Error( 'img tag not found in the figure with mw:Image/Thumb for id: ' + this.node.attributes.id );
	}

this.node.attributes[ 'data-mw' ] will be undefined if the input to adaptation comes from VE without https://gerrit.wikimedia.org/r/c/mediawiki/extensions/VisualEditor/+/446575

or... the inline image does not have caption. This is not handled well in the code

Change 447750 had a related patch set uploaded (by Santhosh; owner: Santhosh):
[mediawiki/services/cxserver@master] Fix error when inline images does not have caption

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

Error in Production:

MT processing error: Error: img tag not found in the figure with mw:Image/Thumb for id: undefined
    at MWImage.<anonymous> (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/translationunits/MWImage.js:90:9)
    at next (native)
    at resume (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:277:21)
    at resumeNext (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:287:26)
    at /srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:289:3
    at spawn (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:272:9)
    at MWImage.adapt (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:301:10)
    at tags.forEach (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/lineardoc/TextBlock.js:417:31)
    at Array.forEach (native)
    at textChunks.forEach (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/lineardoc/TextBlock.js:414:8)
    at Array.forEach (native)
    at TextBlock.adapt (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/lineardoc/TextBlock.js:410:18)
    at Doc.<anonymous> (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/lineardoc/Doc.js:292:21)
    at next (native)
    at resume (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:277:21)
    at resumeNext (/srv/deployment/cxserver/deploy-cache/revs/d378d27bf6a5706b4911ff8947e6f166685a2d9d/src/lib/util.js:287:26)

Examples of where this can be tested are:

  • en:MLS_Cup_Playoffs
  • en:Uma_Thurman

Change 447750 merged by jenkins-bot:
[mediawiki/services/cxserver@master] Fix error when inline images does not have caption

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

Petar.petkovic renamed this task from Adaptation will certainly fail for inline images to Adaptation fails for inline images without caption.Jul 25 2018, 8:11 AM
Petar.petkovic updated the task description. (Show Details)
Petar.petkovic removed a subscriber: gerritbot.

Are you sure about this?

I have updated title and description to match with your comments.

Mentioned in SAL (#wikimedia-operations) [2018-07-26T04:08:26Z] <kartik@deploy1001> Started deploy [cxserver/deploy@3c99775]: Update cxserver to e98c81vb (T200283)

Mentioned in SAL (#wikimedia-operations) [2018-07-26T04:13:38Z] <kartik@deploy1001> Finished deploy [cxserver/deploy@3c99775]: Update cxserver to e98c81vb (T200283) (duration: 05m 12s)