{"record":{"id":"adda039be4b47f15","repo":"nwjs/nw.js","slug":"invalid-option-adda03","errorCode":null,"errorMessage":"Invalid option.","messagePattern":"Invalid option\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/shortcut/shorcut.js","lineNumber":25,"sourceCode":"// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co\n// pies of the Software, and to permit persons to whom the Software is furnished\n// to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in\n// all copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM\n// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES\n// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH\n// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar v8_util = process.binding('v8_util');\n\nfunction Shortcut(option) {\n  if (typeof option != 'object')\n    throw new TypeError('Invalid option.');\n\n  if (!option.hasOwnProperty('key'))\n    throw new TypeError(\"Shortcut requires 'key' to specify key combinations.\");\n\n  option.key = String(option.key);\n  this.key = option.key;\n\n  if (option.hasOwnProperty('active')) {\n    if (typeof option.active != 'function')\n      throw new TypeError(\"'active' must be a valid function.\");\n    else\n      this.active = option.active;\n  }\n\n  if (option.hasOwnProperty('failed')) {\n    if (typeof option.failed != 'function')\n      throw new TypeError(\"'failed' must be a valid function.\");\n    else","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/shortcut/shorcut.js#L7-L43","documentation":"Shortcut's constructor requires its argument to be an object (`typeof option != 'object'` → TypeError). This mirrors MenuItem's option check. As with MenuItem, `typeof null === 'object'`, so null slips past this guard and fails later when `.hasOwnProperty('key')` is called on null.","triggerScenarios":"Calling new nw.Shortcut(), new nw.Shortcut('Ctrl+A'), or new nw.Shortcut(undefined). Passing the key string directly instead of an options object is the most common case.","commonSituations":"Developers assume the constructor takes the key string positionally. API examples that show `{key}` in docs being misread as taking a string. Migration from libraries with positional constructors.","solutions":["Pass an options object: `new nw.Shortcut({ key: 'Ctrl+A', active: fn })`.","If you only have a key string, wrap it: `new nw.Shortcut({ key: str })`.","Do not pass null; supply a real object with at least a `key` property."],"exampleFix":"// before\nnew nw.Shortcut('Ctrl+A'); // throws\nnew nw.Shortcut();         // throws\n\n// after\nnew nw.Shortcut({ key: 'Ctrl+A', active: onActive });","handlingStrategy":"validation","validationCode":"function buildShortcut(opt) {\n  if (opt == null || typeof opt !== 'object' || Array.isArray(opt))\n    throw new TypeError('Shortcut requires an options object');\n  return new nw.Shortcut(opt);\n}","typeGuard":"function isPlainObject(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try { return new nw.Shortcut(opt); }\ncatch (e) {\n  if (e instanceof TypeError && /Invalid option/.test(e.message)) {\n    return new nw.Shortcut({ key: String(opt) }); // coerce a raw key string\n  } throw e;\n}","preventionTips":["Always pass an options object with at least a `key`.","Reject null/arrays before constructing.","Do not pass the key string positionally."],"tags":["nwjs","shortcut","constructor","validation"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}