Closed Bug 1291695 Opened 8 years ago Closed 8 years ago

Missing { references } can break bindings

Categories

(L20n :: JS Library, defect)

defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: Pike, Assigned: stas)

References

Details

(Whiteboard: [gecko-l20n])

Attachments

(1 file)

40 bytes, text/x-github-pull-request
zbraniecki
: review+
Details | Review
In bug 1288406 comment 34, we found a crash in MessageContext.jsm:


ReferenceError: Unknown entity: brand-shorter-name
Stack trace:
EntityReference@resource://gre/modules/IntlMessageContext.jsm:946:16
Value@resource://gre/modules/IntlMessageContext.jsm:1025:26
Pattern@resource://gre/modules/IntlMessageContext.jsm:1127:16
Value@resource://gre/modules/IntlMessageContext.jsm:1010:19
Value@resource://gre/modules/IntlMessageContext.jsm:1032:21
Pattern@resource://gre/modules/IntlMessageContext.jsm:1127:16

We should never crash, 'cause that takes the browser down.
The output you're seeing is a console.error that we should probably remove at some point.

That said, there's definitely an issue here related to how we're handling broken { references } to other entities.  Half of the menubar just disappears when I misspell a single reference in bug 1288406.

I'll investigate.
Assignee: nobody → stas
Summary: MessageContext shouldn't cause JS Exceptions → Missing { references } can break bindings
So, I tried to debug it, and I'm not sure if I found the same bug or different, but I noticed that if I add a broken reference to "file-menu" xul/label, it breaks completely.

There are two parts. One is a graceful recovery - for xul it may be that displaying ID in label is better than as value - and the other is why we didn't show the broken attribute.

Oh boy, what a ride.

So, the problem is this line: https://github.com/l20n/l20n.js/blob/69fe01ff11422ffd9a0e68d91eaffa6fa8e4c321/src/lib/format.js#L53

Basically, we don't differentiate between types of errors and in this scenario, if the first bundle errors with "File menu brand-shorter-name2", and the latter with fallback to ID, we take the latter because previous had errors.

Not sure how we want to fix that and if it's this bug, but I couldn't reproduce losing multiple translations due to an error in one entity.
Thanks for investigating.  I'll try the same scenario tomorrow to refresh my memory, and will try to provide a helpful opinion.
(In reply to Zibi Braniecki [:gandalf][:zibi] from comment #2)

> There are two parts. One is a graceful recovery - for xul it may be that
> displaying ID in label is better than as value - and the other is why we
> didn't show the broken attribute.

Let's fix the first issue in bug 1288443 and discuss the second one here.

> So, the problem is this line:
> https://github.com/l20n/l20n.js/blob/
> 69fe01ff11422ffd9a0e68d91eaffa6fa8e4c321/src/lib/format.js#L53
> 
> Basically, we don't differentiate between types of errors and in this
> scenario, if the first bundle errors with "File menu brand-shorter-name2",
> and the latter with fallback to ID, we take the latter because previous had
> errors.

Would it make sense to differentiate between L10nErrors (meaning: "this entity is missing") and other Errors returned by MessageContext (they're all standard JS errors: ReferenceError, RangeError, TypeError)?

I'll try to prepare a patch today to demonstrate what I mean.

> Not sure how we want to fix that and if it's this bug, but I couldn't
> reproduce losing multiple translations due to an error in one entity.

Me neither.
Attached file Pull request
Here's what I've been thinking about, expressed in code.
Attachment #8805679 - Flags: review?(gandalf)
Attachment #8805679 - Flags: review?(gandalf) → review+
https://hg.mozilla.org/projects/larch/rev/9d04883619b221b65d67ce66b168c1ec1dc4566c
Bug 1291695 - Improve fallback strategy based on the type of error. r=gandalf
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
(In reply to Staś Małolepszy :stas from comment #5)

> Here's what I've been thinking about, expressed in code.

For archiving purposes:

The patch differentiates between fatal errors caused by missing translations and non-fatal formatting errors returned by MessageContext.

The fallback strategy is now to trigger the loading of the next language only if there were fatal errors in the current language. Translations with only non-fatal errors are considered to be good fallback values.  If a fatal error in another translation triggers fallback, the Localization will prefer translations from the fallback bundle if translations from the first bundle had non-fatal errors.

So to sum up:

 - non-fatal (formatting) errors don't trigger fallback on their own
 - instead they return strings with as much of the translation as possible
 - a fallback might be triggered by another missing translation in the same call to formatValues/formatEntities
 - in this case, we try to find a better value also for the non-missing but broken translations from the first bundle.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: