{"record":{"id":"3af561837805136c","repo":"nwjs/nw.js","slug":"invalid-option-3af561","errorCode":null,"errorMessage":"Invalid option.","messagePattern":"Invalid option\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_menuitem.js","lineNumber":24,"sourceCode":"\nvar menuItems = { objs : {}, clickEvent: {} };\nmenuItems.clickEvent = bindingUtil.createCustomEvent(\"NWObjectclick\", false, false);\nmenuItems.clickEvent.addListener(function(id) {\n  var obj = menuItems.objs[id];\n  if (!obj)\n    return;\n  try{obj.click && obj.click()}catch(e){console.error(e)}\n  try{obj.emit('click')}catch(e){console.error(e)}\n});\n\nfunction MenuItem(option) {\n  if (!(this instanceof MenuItem)) {\n    return new MenuItem(option);\n  }\n  EventEmitter.apply(this);\n\n  if (typeof option != 'object')\n    throw new TypeError('Invalid option.');\n\n  if (!option.hasOwnProperty('type'))\n    option.type = 'normal';\n\n  if (option.type != 'normal' &&\n      option.type != 'checkbox' &&\n      option.type != 'separator')\n    throw new TypeError('Invalid MenuItem type: ' + option.type);\n\n  if (option.type == 'normal' || option.type == 'checkbox') {\n    if (option.type == 'checkbox')\n      option.checked = Boolean(option.checked);\n\n    if (!option.hasOwnProperty('label'))\n      throw new TypeError('A normal MenuItem must have a label');\n    else\n      option.label = String(option.label);\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_menuitem.js#L6-L42","documentation":"Thrown by the nw.MenuItem constructor when the option argument is not an object (typeof check). MenuItem reads type, label, icon, etc. from the option object, so a primitive or undefined is rejected up front.","triggerScenarios":"Calling `new nw.MenuItem()`, `new nw.MenuItem(null)`, `new nw.MenuItem('Quit')`, or `new nw.MenuItem(0)`.","commonSituations":"Passing a bare label string as in some other menu APIs; forgetting to wrap configuration in an object.","solutions":["Wrap in an object: `new nw.MenuItem({ label: 'Quit' })`.","Default the argument: `new nw.MenuItem(opt || { type: 'separator' })`."],"exampleFix":"// before\nnew nw.MenuItem('Quit');\n// after\nnew nw.MenuItem({ label: 'Quit' });","handlingStrategy":"validation","validationCode":"if (typeof option !== 'object' || option === null) option = {};","typeGuard":"function isMenuItemOption(o) { return o && typeof o === 'object'; }","tryCatchPattern":"try { new nw.MenuItem(opt); } catch (e) { if (/Invalid option/.test(e.message)) new nw.MenuItem({ label: '' }); else throw e; }","preventionTips":["Always wrap label/config in an object.","Default the argument to a minimal object."],"tags":["menuitem","constructor","type-check","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}