{"record":{"id":"8423d35a7ca75a65","repo":"nwjs/nw.js","slug":"shortcut-requires-key-to-specify-key-combination-8423d3","errorCode":null,"errorMessage":"Shortcut requires 'key' to specify key combinations.","messagePattern":"Shortcut requires 'key' to specify key combinations\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_shortcut.js","lineNumber":158,"sourceCode":"}\n\nfunction unregisterLocal(shortcut) {\n  var localKey = normalizeLocal(shortcut._accelerator);\n  delete handlers[localKey];\n}\n\nfunction Shortcut(option) {\n  if (!(this instanceof Shortcut)) {\n    return new Shortcut(option);\n  }\n\n  EventEmitter.apply(this, arguments);\n\n  if (typeof option != 'object')\n    throw new TypeError(OPTION_INVALID);\n\n  if (!option.key)\n    throw new TypeError(OPTION_KEY_REQUIRED);\n\n  if (option.hasOwnProperty('active')) {\n    if (typeof option.active != 'function')\n      throw new TypeError(OPTION_ACTIVE_INVALID);\n  }\n\n  if (option.hasOwnProperty('failed')) {\n    if (typeof option.failed != 'function')\n      throw new TypeError(OPTION_FAILED_INVALID);\n  }\n\n  var self = this;\n\n  this.on('active', function() {\n    if (!self.active) return;\n    if (typeof self.active != 'function')\n      throw new TypeError(OPTION_ACTIVE_INVALID);\n    self.active.apply(self, arguments);","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_shortcut.js#L140-L176","documentation":"Thrown by the Shortcut constructor when option is an object but has no truthy 'key' property (!option.key). The key is the accelerator string (e.g. 'ctrl+a') and is the single required field; without it the Shortcut cannot be bound to a hardware combination.","triggerScenarios":"new nw.Shortcut({ active: fn }) (key omitted); new nw.Shortcut({ key: '' }) (empty string is falsy); new nw.Shortcut({ key: null }); new nw.Shortcut({}) (empty object).","commonSituations":"Building the options object conditionally where the key assignment was skipped; destructuring or spreading that dropped the key field; passing a config object intended for a different API.","solutions":["Ensure the options object includes a non-empty key string, e.g. { key: 'ctrl+a' }.","Validate that option.key is a truthy string before calling new nw.Shortcut()."],"exampleFix":"// before\nnew nw.Shortcut({ active: handler });\n// after\nnew nw.Shortcut({ key: 'ctrl+a', active: handler });","handlingStrategy":"validation","validationCode":"if (!option || typeof option.key !== 'string' || option.key.length === 0) {\n  throw new TypeError('Shortcut requires a non-empty key string');\n}","typeGuard":"function hasShortcutKey(o) { return !!o && typeof o === 'object' && typeof o.key === 'string' && o.key.length > 0; }","tryCatchPattern":null,"preventionTips":["Always include key as a non-empty string in the options object.","When building options dynamically, assert key presence before construction.","Treat key as the one mandatory field of the Shortcut config."],"tags":["nwjs","shortcut","validation","required-field"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}