hcengineering/platform · error · Error

Notification id is required

Error message

Notification id is required

What it means

NotificationProcessor.create builds a Notification object from a CreateNotificationEvent and an optional explicit id. The event's notificationId is preferred, falling back to the optional second `id` argument. If neither source yields a value (null or undefined), the processor cannot key the notification and throws this error.

Source

Thrown at foundations/communication/packages/shared/src/processor.ts:117

      lastView: event.updates.lastView ?? context.lastView,
      lastUpdate: event.updates.lastUpdate ?? context.lastUpdate,
      lastNotify: event.updates.lastNotify ?? context.lastNotify
    }
  }

  static remove (context: NotificationContext, event: RemoveNotificationContextEvent): NotificationContext | undefined {
    if (context.account !== event.account || context.id !== event.contextId) return context
    return undefined
  }
}

// eslint-disable-next-line @typescript-eslint/no-extraneous-class
export class NotificationProcessor {
  static create (event: CreateNotificationEvent, id?: NotificationID): Notification {
    const notificationId: NotificationID | undefined = event.notificationId ?? (id as NotificationID)

    if (notificationId == null) {
      throw new Error('Notification id is required')
    }
    return {
      id: notificationId,
      cardId: event.cardId,
      contextId: event.contextId,
      account: event.account,
      type: event.notificationType,
      read: event.read,
      content: event.content ?? {},
      created: event.date ?? new Date(),
      messageId: event.messageId,
      creator: event.creator,
      blobId: event.blobId
    }
  }
}

function applyPatchEvent (message: Message, event: PatchEvent): Message | undefined {

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Set notificationId on the CreateNotificationEvent before calling create
  2. Pass the id as the second argument: NotificationProcessor.create(event, someNotificationId)
  3. Generate an id at the call site (e.g. the ID factory/uuid used elsewhere in the codebase) and provide it to create

Example fix

// before
const notification = NotificationProcessor.create({ cardId, contextId, account });
// after
const notification = NotificationProcessor.create({ cardId, contextId, account, notificationId: generateNotificationId() });
Defensive patterns

Strategy: validation

Validate before calling

if (event.notificationId == null && id == null) throw new Error('notificationId must be provided before calling NotificationProcessor.create');

Type guard

function hasNotificationId(e: CreateNotificationEvent, id?: NotificationID): e is CreateNotificationEvent & { notificationId: NotificationID } { return e.notificationId != null || id != null; }

Try / catch

let notification;
try { notification = NotificationProcessor.create(event, id); }
catch (e) { if ((e as Error).message === 'Notification id is required') { /* supply/generate id and retry */ } else throw e; }

Prevention

When it happens

Trigger: Calling NotificationProcessor.create(event) with an event whose notificationId is null/undefined AND omitting the second `id` argument, or passing undefined/null explicitly for it.

Common situations: Constructing a CreateNotificationEvent by hand and forgetting to assign notificationId; a deserialized event payload missing the field; refactored call sites that dropped the second argument after relying on it.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/36cda3f0b5e064de. Report an issue: GitHub.