{"record":{"id":"3008e602dc762cd9","repo":"nwjs/nw.js","slug":"click-must-be-a-valid-function-3008e6","errorCode":null,"errorMessage":"'click' must be a valid Function","messagePattern":"'click' must be a valid Function","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_tray.js","lineNumber":56,"sourceCode":"    option.icon = nwNative.getAbsolutePath(option.icon);\n  }\n\n  if (option.hasOwnProperty('alticon')) {\n    option.shadowAlticon = String(option.alticon);\n    option.alticon = nwNative.getAbsolutePath(option.alticon);\n  }\n\n  if (option.hasOwnProperty('iconsAreTemplates'))\n    option.iconsAreTemplates = Boolean(option.iconsAreTemplates);\n  else\n    option.iconsAreTemplates = true;\n\n  if (option.hasOwnProperty('tooltip'))\n    option.tooltip = String(option.tooltip);\n\n  if (option.hasOwnProperty('click')) {\n    if (typeof option.click != 'function') {\n      throw new TypeError(\"'click' must be a valid Function\");\n    } else {\n      this.click = option.click;\n    }\n   }\n\n  if (option.hasOwnProperty('menu')) {\n    if (option.menu.constructor.name != 'Menu')\n      throw new TypeError(\"'menu' must be a valid Menu\");\n\n    // Transfer only object id\n    privates(this).menu = option.menu;\n    option.menu = option.menu.id;\n  }\n  \n  var id = nw.Obj.allocateId();\n  this.id = id;\n  privates(this).option = option;\n","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_tray.js#L38-L74","documentation":"Thrown by the Tray constructor when option.hasOwnProperty('click') is true but typeof option.click !== 'function'. The click callback is wired into the native tray click event; it must be callable. Validated eagerly at construction.","triggerScenarios":"new nw.Tray({ title: 'x', click: 'onClick' }) (string); new nw.Tray({ title: 'x', click: true }); click loaded from JSON config.","commonSituations":"JSON-deserialized config (no function type); referencing a handler by name string; setting click to a truthy non-function as a placeholder.","solutions":["Pass a function: { title: 'x', click: () => {} }.","Resolve handlers by name from a registry when loading JSON config.","Omit click entirely if you do not need click handling."],"exampleFix":"// before\nnew nw.Tray({ title: 'x', click: 'onClick' });\n// after\nnew nw.Tray({ title: 'x', click: onClick });","handlingStrategy":"type-guard","validationCode":"if ('click' in option && typeof option.click !== 'function') {\n  throw new TypeError('option.click must be a function');\n}","typeGuard":"function isClickValid(o) { return !o.hasOwnProperty('click') || typeof o.click === 'function'; }","tryCatchPattern":null,"preventionTips":["Pass a function reference for click.","Resolve handler names from JSON config before construction.","Omit click if you do not need click handling."],"tags":["nwjs","tray","validation","callback"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}