{"record":{"id":"bae606770402dda2","repo":"nwjs/nw.js","slug":"invalid-option","errorCode":null,"errorMessage":"Invalid option.","messagePattern":"Invalid option\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/menuitem/menuitem.js","lineNumber":25,"sourceCode":"//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co\n// pies of the Software, and to permit persons to whom the Software is furnished\n//  to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in al\n// 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');\n\nfunction MenuItem(option) {\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":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/menuitem/menuitem.js#L7-L43","documentation":"MenuItem's constructor requires its argument to be an object. `typeof option != 'object'` throws a TypeError for strings, numbers, booleans, undefined, and functions. Note that JS quirk: `typeof null === 'object'`, so passing null bypasses this guard and will instead fail later on `null.hasOwnProperty` — a different error.","triggerScenarios":"Calling new nw.MenuItem(), new nw.MenuItem('label'), new nw.MenuItem(42), or new nw.MenuItem(undefined).","commonSituations":"Developers assume the constructor takes a label string (like some other UI libraries). Forgetting the option object entirely. Migrating from an API that accepted positional or string args.","solutions":["Pass an options object: `new nw.MenuItem({ type: 'normal', label: 'Open' })`.","If you only have a label string, wrap it: `new nw.MenuItem({ label: str })`.","Never pass null; either omit the argument or supply a real object."],"exampleFix":"// before\nnew nw.MenuItem('Open'); // throws\nnew nw.MenuItem();      // throws\n\n// after\nnew nw.MenuItem({ label: 'Open' });","handlingStrategy":"validation","validationCode":"function buildItem(option) {\n  if (option == null || typeof option !== 'object' || Array.isArray(option))\n    throw new TypeError('MenuItem requires an options object');\n  return new nw.MenuItem(option);\n}","typeGuard":"function isPlainObject(v) {\n  return v != null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try { return new nw.MenuItem(option); }\ncatch (e) {\n  if (e instanceof TypeError && /Invalid option/.test(e.message)) {\n    return new nw.MenuItem({ label: String(option) });\n  } throw e;\n}","preventionTips":["Always pass an options object, not a string or undefined.","Reject null/arrays explicitly before constructing.","Use TypeScript/JSDoc types to catch this at edit time."],"tags":["nwjs","menuitem","constructor","validation"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}