{"record":{"id":"f07e032726e906df","repo":"nwjs/nw.js","slug":"menu-property-requries-a-valid-menu","errorCode":null,"errorMessage":"'menu' property requries a valid Menu","messagePattern":"'menu' property requries a valid Menu","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/tray/tray.js","lineNumber":133,"sourceCode":"Tray.prototype.__defineSetter__('iconsAreTemplates', function(val) {\n  this.handleSetter('iconsAreTemplates', 'SetIconsAreTemplates', Boolean, val);\n});\n\nTray.prototype.__defineGetter__('tooltip', function() {\n  return this.handleGetter('tooltip');\n});\n\nTray.prototype.__defineSetter__('tooltip', function(val) {\n  this.handleSetter('tooltip', 'SetTooltip', String, val);\n});\n\nTray.prototype.__defineGetter__('menu', function() {\n  return v8_util.getHiddenValue(this, 'menu');\n});\n\nTray.prototype.__defineSetter__('menu', function(val) {\n  if (v8_util.getConstructorName(val) != 'Menu')\n    throw new TypeError(\"'menu' property requries a valid Menu\");\n\n  v8_util.setHiddenValue(this, 'menu', val);\n  nw.callObjectMethod(this, 'SetMenu', [ val.id ]);\n});\n\nTray.prototype.remove = function() {\n  nw.callObjectMethod(this, 'Remove', []);\n}\n\nTray.prototype.handleEvent = function(ev) {\n if (ev == 'click') {\n   // Emit click handler\n   if (typeof this.click == 'function'){\n     this.click();\n   }\n }\n // Emit generate event handler\n exports.Base.prototype.handleEvent.apply(this, arguments);","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/tray/tray.js#L115-L151","documentation":"Thrown by the nw.Tray 'menu' setter when the assigned value's constructor name is not 'Menu'. This is the runtime-mutation equivalent of the constructor guard: tray.menu can only be reassigned to a real nw.Menu instance.","triggerScenarios":"Running `tray.menu = null`, `tray.menu = { items: [] }`, or `tray.menu = somePlainObject` after construction.","commonSituations":"Clearing the menu by assigning null instead of removing it; replacing the menu with a freshly parsed JSON object.","solutions":["Assign a nw.Menu instance: `tray.menu = new nw.Menu()`.","To clear, assign a new empty Menu rather than null or undefined."],"exampleFix":"// before\ntray.menu = { items: [] };\n// after\ntray.menu = new nw.Menu();","handlingStrategy":"type-guard","validationCode":"if (val && !(val instanceof nw.Menu)) throw new Error('tray.menu requires a nw.Menu');","typeGuard":"function isMenuInstance(v) { return v && v.constructor && v.constructor.name === 'Menu'; }","tryCatchPattern":"try { tray.menu = val; } catch (e) { if (/Menu/.test(e.message)) tray.menu = new nw.Menu(); else throw e; }","preventionTips":["Never assign null or plain objects to tray.menu.","Build a replacement Menu instance before swapping."],"tags":["tray","setter","type-check","menu","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}