{"record":{"id":"2cb031e7343650c1","repo":"nwjs/nw.js","slug":"failed-must-be-a-valid-function-2cb031","errorCode":null,"errorMessage":"'failed' must be a valid function.","messagePattern":"'failed' must be a valid function\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_shortcut.js","lineNumber":167,"sourceCode":"    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);\n  });\n\n  this.on('failed', function() {\n    if (!self.failed) return;\n    if (typeof self.failed != 'function')\n      throw new TypeError(OPTION_FAILED_INVALID);\n    self.failed.apply(self, arguments);\n  });\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_shortcut.js#L149-L185","documentation":"Thrown by the Shortcut constructor when option.hasOwnProperty('failed') is true but typeof option.failed !== 'function'. The 'failed' callback is invoked when registration or unregistration of the hotkey fails, so it must be callable. Validated eagerly at construction time.","triggerScenarios":"new nw.Shortcut({ key: 'ctrl+a', failed: 'errHandler' }) (string); new nw.Shortcut({ key: 'ctrl+a', failed: {} }); failed loaded from a JSON-deserialized config.","commonSituations":"JSON config round-trip losing function values; passing a config object shared with another library that uses a different shape; forgetting that 'failed' must be a function not a description string.","solutions":["Pass a real function for failed: { key: 'ctrl+a', failed: (err) => console.error(err) }.","Resolve the handler from a name registry when loading config from JSON.","Omit failed if you do not need failure notification; it is optional."],"exampleFix":"// before\nnew nw.Shortcut({ key: 'ctrl+a', failed: 'handleErr' });\n// after\nnew nw.Shortcut({ key: 'ctrl+a', failed: handleErr });","handlingStrategy":"type-guard","validationCode":"if ('failed' in option && typeof option.failed !== 'function') {\n  throw new TypeError('option.failed must be a function');\n}","typeGuard":"function isFailedValid(o) { return !o.hasOwnProperty('failed') || typeof o.failed === 'function'; }","tryCatchPattern":null,"preventionTips":["Provide a real error-handling function for failed.","Resolve handler names from JSON config before construction.","Omit failed if you do not need failure callbacks."],"tags":["nwjs","shortcut","validation","callback"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}