Bug: Sidebar extensions cause an error trying to translate the sidebar switcher panel item's shortcut
Status: NEW
Priority: P5
Created: 2023-04-07 08:03:35+00:00
Resolved: 2023-04-10 16:59:29+00:00

### STR
1. Install an extension that includes a sidebar and a keyboard shortcut for opening it, like [Notes by Firefox](https://addons.mozilla.org/firefox/addon/notes-by-firefox)
2. Go to about:addons, click the gear icon, Manage Keyboard Shortcuts
3. Find the shortcut for opening the extension's sidebar document
4. Configure it such that the printing key isn't included in [keys.properties](https://searchfox.org/mozilla-central/source/toolkit/locales/en-US/chrome/global/keys.properties), e.g. `Shift+Alt+1`
5. Restart Firefox, open the browser console, open the sidebar, and open the sidebar switcher panel (click the button above the sidebar content with the label of the sidebar, e.g. Bookmarks)

### Expected
There shouldn't need to be an error for a feature like this that the user is expected to use. Actually, I think some extensions include a default keyboard shortcut that causes this error, though I can't remember for sure if I set them myself.

### Actual
There is an error locating the printing key in the key bundles. It ends up just eliding the `VK_` from the key code for the purpose of the accel text. The exception itself is caught but [logs an error](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/toolkit/modules/ShortcutUtils.sys.mjs#133) anyway.

Basically [SidebarUI._ensureShortcutsShown](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/browser/base/content/browser-sidebar.js#260) calls [SidebarUI.updateShortcut](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/browser/base/content/browser-sidebar.js#240), which calls [ShortcutUtils.prettifyShortcut](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/toolkit/modules/ShortcutUtils.sys.mjs#47), which calls [ShortcutUtils.getKeyString](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/toolkit/modules/ShortcutUtils.sys.mjs#115), which [tries to find the shortcut](https://searchfox.org/mozilla-central/rev/c244b16815d1fc827d141472b9faac5610f250e7/toolkit/modules/ShortcutUtils.sys.mjs#128-135) in a string bundle and logs the error if that throws.

Because this method can now be called for a limited but large set of keys other than the shortcuts built into Firefox, it seems like a key not being found in keys.properties is an expected behavior. Logging this kind of error is useful for developers working on Firefox itself, but logging it for many extension shortcuts makes for false positives. So, I guess the bundle should either include all the keys that are allowed for extension keyboard shortcuts (not sure where that list is, but it seems like only printing keys and a few special keys), or the method should have a param to opt out of logging, for callers that expect the bundle method to throw?

Or maybe it's simplest to just add some logic to check if the key code is a valid extension keyboard shortcut key, and then don't log the error if so. It's just an error log at the end of the day, so I suppose it may not be worth fixing if the fix is too much effort