{"record":{"id":"5bef832baaf67cab","repo":"nwjs/nw.js","slug":"must-set-title-or-icon-field-in-option","errorCode":null,"errorMessage":"Must set 'title' or 'icon' field in option","messagePattern":"Must set 'title' or 'icon' field in option","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/tray/tray.js","lineNumber":28,"sourceCode":"//\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 Tray(option) {\n  if (typeof option != 'object')\n    throw new TypeError('Invalid option');\n\n  if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon'))\n    throw new TypeError(\"Must set 'title' or 'icon' field in option\");\n\n  if (!option.hasOwnProperty('title'))\n    option.title = '';\n  else\n    option.title = String(option.title);\n\n  if (option.hasOwnProperty('icon')) {\n    option.shadowIcon = String(option.icon);\n    option.icon = nw.getAbsolutePath(option.icon);\n  }\n\n  if (option.hasOwnProperty('alticon')) {\n    option.shadowAlticon = String(option.alticon);\n    option.alticon = nw.getAbsolutePath(option.alticon);\n  }\n\n  if (option.hasOwnProperty('iconsAreTemplates'))\n    option.iconsAreTemplates = Boolean(option.iconsAreTemplates);","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/tray/tray.js#L10-L46","documentation":"Thrown by the nw.Tray constructor when the options object has neither a 'title' nor an 'icon' property. A tray entry must show something — text or an icon — so providing an empty or unrelated options object is rejected.","triggerScenarios":"Calling `new nw.Tray({})`, `new nw.Tray({ tooltip: 'x' })`, or `new nw.Tray({ click: fn })` with no title/icon.","commonSituations":"Building the options object conditionally and both branches skipped; renaming the property to 'name' or 'text' instead of 'title'.","solutions":["Add at least one of title or icon: `new nw.Tray({ icon: 'icon.png' })`.","If using an icon, ensure the path is a string and resolvable."],"exampleFix":"// before\nnew nw.Tray({ tooltip: 'My App' });\n// after\nnew nw.Tray({ title: 'My App', tooltip: 'My App' });","handlingStrategy":"validation","validationCode":"if (!option.hasOwnProperty('title') && !option.hasOwnProperty('icon')) {\n  throw new Error('Tray requires title or icon');\n}","typeGuard":"function hasTitleOrIcon(o) { return o && (typeof o.title !== 'undefined' || typeof o.icon !== 'undefined'); }","tryCatchPattern":"try { new nw.Tray(opt); } catch (e) { if (/title or icon/.test(e.message)) opt.title = 'App'; else throw e; }","preventionTips":["Make title or icon a required field in your tray config schema.","Validate the option object shape before construction."],"tags":["tray","constructor","required-field","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}