{"record":{"id":"763adefc711f66f3","repo":"hcengineering/platform","slug":"notification-context-id-is-required","errorCode":null,"errorMessage":"Notification context id is required","messagePattern":"Notification context id is required","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"foundations/communication/packages/shared/src/processor.ts","lineNumber":82,"sourceCode":"      language: event.language,\n      reactions: {},\n      attachments: [],\n      threads: []\n    }\n  }\n\n  static applyPatch (message: Message, patchEvent: PatchEvent): Message | undefined {\n    return applyPatchEvent(message, patchEvent)\n  }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class NotificationContextProcessor {\n  static create (event: CreateNotificationContextEvent, id?: ContextID): NotificationContext {\n    const contextId: ContextID | undefined = event.contextId ?? id\n\n    if (contextId == null) {\n      throw new Error('Notification context id is required')\n    }\n    return {\n      id: contextId,\n      cardId: event.cardId,\n      account: event.account,\n      lastView: event.lastView,\n      lastUpdate: event.lastUpdate,\n      lastNotify: event.lastNotify,\n      notifications: withTotal([] as Notification[])\n    }\n  }\n\n  static update (context: NotificationContext, event: UpdateNotificationContextEvent): NotificationContext {\n    if (context.account !== event.account || context.id !== event.contextId) return context\n    return {\n      ...context,\n      lastView: event.updates.lastView ?? context.lastView,\n      lastUpdate: event.updates.lastUpdate ?? context.lastUpdate,","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/communication/packages/shared/src/processor.ts#L64-L100","documentation":"NotificationContextProcessor.create resolves the context id from event.contextId or the optional id parameter and throws this Error if both are null/undefined. A NotificationContext cannot be constructed without a stable identity.","triggerScenarios":"Calling NotificationContextProcessor.create(event) where event.contextId is null/undefined and no `id` argument is provided.","commonSituations":"Creating notification contexts from client events that omit contextId; passing an undefined id variable at runtime despite TypeScript typing; deserialization dropping undefined fields; fixtures for tests missing contextId.","solutions":["Provide event.contextId when constructing the event.","Pass the id explicitly as the second argument: NotificationContextProcessor.create(event, contextId).","Generate a context id (UUID) at creation time if the event legitimately lacks one.","Add ingestion validation so events missing contextId are rejected/reported at the boundary instead of deep in the processor."],"exampleFix":"// before\nconst ctx = NotificationContextProcessor.create({ cardId, account } as CreateNotificationContextEvent)\n// Error: Notification context id is required\n// after\nconst ctx = NotificationContextProcessor.create({ cardId, account, contextId: crypto.randomUUID() } as CreateNotificationContextEvent)","handlingStrategy":"type-guard","validationCode":"function assertContextId(event: CreateNotificationContextEvent, id?: ContextID): ContextID {\n  const cid = event.contextId ?? id\n  if (cid == null) throw new Error('Provide event.contextId or an explicit id to NotificationContextProcessor.create')\n  return cid\n}","typeGuard":"function hasContextId(event: CreateNotificationContextEvent, id?: ContextID): event is CreateNotificationContextEvent & { contextId: ContextID } {\n  return (event.contextId ?? id) != null\n}","tryCatchPattern":"try {\n  const ctx = NotificationContextProcessor.create(event, id)\n} catch (e) {\n  if (e.message === 'Notification context id is required') {\n    return NotificationContextProcessor.create({ ...event, contextId: crypto.randomUUID() }, id)\n  }\n  throw e\n}","preventionTips":["Always set contextId when constructing CreateNotificationContextEvent.","Pass the explicit id argument when the event lacks one.","Validate contextId at ingestion to fail fast with clear logs.","Ensure deserializers preserve contextId (undefined fields can be dropped in JSON round-trips)."],"tags":["validation","notifications","factory","shared"],"backgroundTag":"missing-required-field","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}