Closed Bug 2066877 Opened 1 month ago Closed 25 days ago

L10nCache.add() throws on an unknown Fluent ID instead of reporting it

Categories

(Firefox :: Address Bar, task, P3)

task

Tracking

()

RESOLVED FIXED
157 Branch
Tracking Status
firefox157 --- fixed

People

(Reporter: dao, Assigned: rootzero.brain, Mentored)

References

Details

(Keywords: good-first-bug, Whiteboard: [lang=js][sng])

Attachments

(1 file)

Filing as a good first bug to learn workflows.

L10nCache.add() in browser/components/urlbar/content/L10nCache.mjs guards against l10n.formatMessages() returning an empty array, but not against it resolving with a null message, which is what happens when the requested Fluent ID does not exist. The messages[0].value access then throws TypeError: can't access property "value", messages[0] is null, and because add() is awaited while building the urlbar result menu, one unknown ID leaves the whole menu empty instead of dropping a single item. Bug 2066758 is an instance of that.

The fix is to treat a null message the same way the empty array is treated: report it with console.error and return.

Link to the code:
https://searchfox.org/firefox-main/rev/2aa0bcf95c98681376e30d6a9aa4df2b27885abc/browser/components/urlbar/content/L10nCache.mjs#122-131

A unit test belongs in browser/components/urlbar/tests/unit/test_l10nCache.js, which builds a Localization over a mock file source via its initL10n() helper: adding an ID that the mock source does not define should leave the cache empty rather than reject.

To verify the fix:

./mach test browser/components/urlbar/tests/unit/test_l10nCache.js

Tutorial to contribute:
https://firefox-source-docs.mozilla.org/contributing/contribution_quickref.html
https://firefox-source-docs.mozilla.org/contributing/stack_quickref.html

Please don't ask for the bug to be assigned. It will be automatically assigned to the first patch.

See Also: → 2066758
Severity: -- → N/A
Priority: -- → P3
Whiteboard: [lang=js] → [lang=js][sng]
Assignee: nobody → rootzero.brain
Status: NEW → ASSIGNED
Status: ASSIGNED → RESOLVED
Closed: 25 days ago
Resolution: --- → FIXED
Target Milestone: --- → 157 Branch
QA Whiteboard: [search][qa-triage-done-c157/b156]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: