{"record":{"id":"c443d85d5d147706","repo":"nwjs/nw.js","slug":"invalid-menu-type-option-type","errorCode":null,"errorMessage":"Invalid menu type: {option.type}","messagePattern":"Invalid menu type: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/menu/menu.js","lineNumber":30,"sourceCode":"// l copies or substantial portions of the Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM\n// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES\n// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n//  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH\n// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\n//  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\nvar v8_util = process.binding('v8_util');\nvar EventEmitter = process.EventEmitter;\n\n\nfunction Menu(option) {\n  if (typeof option != 'object')\n    option = { type: 'contextmenu' };\n\n  if (option.type != 'contextmenu' && option.type != 'menubar')\n    throw new TypeError('Invalid menu type: ' + option.type);\n\n  this.type = option.type;\n  v8_util.setHiddenValue(this, 'items', []);\n  nw.allocateObject(this, option);\n}\nrequire('util').inherits(Menu, exports.Base);\n\nMenu.prototype.__defineGetter__('items', function() {\n  return v8_util.getHiddenValue(this, 'items');\n});\n\nMenu.prototype.__defineSetter__('items', function(val) {\n  throw new Error('Menu.items is immutable');\n});\n\nMenu.prototype.append = function(menu_item) {\n  if (v8_util.getConstructorName(menu_item) != 'MenuItem')\n    throw new TypeError(\"Menu.append() requires a valid MenuItem\");","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/menu/menu.js#L12-L48","documentation":"Menu's constructor accepts only two menu types: 'contextmenu' and 'menubar'. If option is not an object it defaults to {type:'contextmenu'}, but once an object is supplied its `type` must be one of those two literals or a TypeError is thrown. The invalid value is interpolated into the message.","triggerScenarios":"Calling new nw.Menu({ type: 'popup' }), { type: 'bar' }, { type: 'menu' }, or any other string. Also { type: undefined } when the object exists but lacks a valid type.","commonSituations":"Developers coming from Electron (where Menu types are different) or guessing the type name ('popup', 'toolbar', 'tray'). Typos like 'context-menu' or 'menu_bar'. Passing an empty object when intending the default (an empty object does NOT default — its type is undefined and throws).","solutions":["Use { type: 'contextmenu' } or { type: 'menubar' }.","Pass no argument (or null) to get the default contextmenu, rather than an empty object.","Check for typos and underscores; the values are single lowercase words."],"exampleFix":"// before\nnew nw.Menu({ type: 'popup' }); // throws\nnew nw.Menu({}); // also throws (type undefined)\n\n// after\nnew nw.Menu({ type: 'contextmenu' });\nnew nw.Menu(); // defaults to contextmenu","handlingStrategy":"validation","validationCode":"var VALID = ['contextmenu', 'menubar'];\nfunction buildMenu(option) {\n  if (option && option.type && VALID.indexOf(option.type) === -1)\n    throw new Error('Invalid menu type: ' + option.type);\n  return new nw.Menu(option);\n}","typeGuard":"function isMenuType(t) { return t === 'contextmenu' || t === 'menubar'; }","tryCatchPattern":"try { return new nw.Menu(option); }\ncatch (e) {\n  if (e instanceof TypeError && /Invalid menu type/.test(e.message)) {\n    return new nw.Menu({ type: 'contextmenu' }); // default fallback\n  } throw e;\n}","preventionTips":["Omit the argument entirely for a default contextmenu.","Never pass an empty object expecting the default.","Whitelist the type before construction."],"tags":["nwjs","menu","constructor","validation"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}