{"record":{"id":"440b584d7e0adc1d","repo":"denoland/deno","slug":"failed-to-construct-notification-1-argument-req","errorCode":null,"errorMessage":"Failed to construct 'Notification': 1 argument required, but only 0 present.","messagePattern":"Failed to construct 'Notification': 1 argument required, but only 0 present\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"cli/rt/desktop.rs","lineNumber":500,"sourceCode":"        return out;\n      }\n      return new TextEncoder().encode(decodeURIComponent(payload));\n    } catch {\n      return null;\n    }\n  }\n\n  const NotificationPrototype = NotificationNative.prototype;\n  Object.setPrototypeOf(NotificationPrototype, EventTarget.prototype);\n\n  const notifications = new Map();\n  // The Web Notifications API constructor is `new Notification(title, options?)`\n  // and shows the notification immediately. The native constructor takes\n  // a third arg for pre-decoded icon bytes so the icon URL → bytes step\n  // happens on the JS side (sync data: URL decoding only).\n  const Notification = function Notification(title, options) {\n    if (arguments.length < 1) {\n      throw new TypeError(\n        \"Failed to construct 'Notification': 1 argument required, but only 0 present.\",\n      );\n    }\n    const t = String(title);\n    const opts = options ?? {};\n    const iconBytes = decodeDataUrlSync(opts.icon);\n    const instance = new NotificationNative(t, opts, iconBytes ?? undefined);\n    if (instance.notificationId !== 0) {\n      notifications.set(instance.notificationId, instance);\n    } else {\n      // Backend didn't show it (no support / failure). The native side\n      // already emitted a NotificationError event; nothing to track here.\n    }\n    return instance;\n  };\n  Object.setPrototypeOf(Notification, NotificationNative);\n  Object.setPrototypeOf(Notification.prototype, NotificationPrototype);\n  Notification.prototype.constructor = Notification;","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/denoland/deno/blob/f7822238cab635a3a19f99f493f675fa81a7f9d8/cli/rt/desktop.rs#L482-L518","documentation":"The Deno desktop runtime implements the Web Notifications API with `new Notification(title, options?)` and shows the notification immediately. Per WebIDL rules the title argument is required; calling the constructor with zero arguments throws this TypeError, matching the exact wording browsers produce.","triggerScenarios":"Calling `new Notification()` with no arguments in the desktop runtime. Note the guard is `arguments.length < 1`, so passing an explicit undefined title does NOT throw (it becomes the string \"undefined\") - only zero arguments triggers it.","commonSituations":"Porting browser code where a helper sometimes omitted the title; copy-pasting an example that destructured options before the title; interactive tutorials constructing notifications before the user typed a title.","solutions":["Pass a title: `new Notification(\"Hello\", options)` - it is coerced with String(), so any defined value works","In wrapper functions, default the title: `new Notification(title ?? \"Update\")`","Validate inputs before constructing when the title comes from user input or config"],"exampleFix":"// before\nconst n = new Notification();\n\n// after\nconst n = new Notification(title ?? \"Update\", { icon: \"/icon.png\" });","handlingStrategy":"type-guard","validationCode":"if (title === undefined || title === null) {\n  throw new TypeError(\"Notification title is required\");\n}","typeGuard":"function isNotificationTitle(t: unknown): t is string {\n  return typeof t === \"string\" && t.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Always call new Notification(title, options?) with an explicit title","Default optional titles in wrappers: title ?? 'Update'","Type the wrapper parameter as string (not string | undefined) so the compiler catches omissions"],"tags":["notifications","desktop","constructor","web-api"],"backgroundTag":"missing-required-argument","analyzedSha":"f7822238cab635a3a19f99f493f675fa81a7f9d8","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}