{"record":{"id":"725934b8ab909db0","repo":"can1357/oh-my-pi","slug":"event-type-is-required","errorCode":null,"errorMessage":"event_type is required","messagePattern":"event_type is required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/streaming.ts","lineNumber":71,"sourceCode":"\treadonly importance?: number | null;\n\treadonly metadata?: Record<string, unknown> | null;\n\treadonly delta?: Record<string, unknown> | null;\n}\n\nexport type MemoryEventDict = {\n\tevent_type: string;\n\tmemory_id: string;\n\ttimestamp: string;\n\tsession_id?: string | null;\n\tcontent?: string | null;\n\tsource?: string | null;\n\timportance?: number | null;\n\tmetadata?: Record<string, unknown> | null;\n\tdelta?: Record<string, unknown> | null;\n};\n\nfunction normalizeEventType(value: string | undefined): EventType {\n\tif (value === undefined) throw new TypeError(\"event_type is required\");\n\tswitch (value) {\n\t\tcase EventType.MEMORY_ADDED:\n\t\tcase EventType.MEMORY_RECALLED:\n\t\tcase EventType.MEMORY_INVALIDATED:\n\t\tcase EventType.MEMORY_CONSOLIDATED:\n\t\tcase EventType.MEMORY_UPDATED:\n\t\t\treturn value;\n\t\tdefault: {\n\t\t\tconst mapped = EventType[value as keyof typeof EventType];\n\t\t\tif (mapped !== undefined) return mapped;\n\t\t\tthrow new RangeError(`Unknown event type: ${value}`);\n\t\t}\n\t}\n}\n\nfunction isSqlQueryBinding(value: unknown): value is SQLQueryBindings {\n\treturn (\n\t\tvalue === null ||","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/streaming.ts#L53-L89","documentation":"normalizeEventType requires an event_type string; when the value is undefined a TypeError is thrown before any enum mapping occurs. Event construction and the eventType accessor both route through this normalizer, so undefined event types cannot enter the stream.","triggerScenarios":"Creating a streaming event object without an event_type field; calling the eventType accessor on an event lacking that property; spreading partial records where event_type was omitted.","commonSituations":"Deserializing events from a source that dropped the event_type column/field; constructing event objects manually with only payload fields; optional-field defaults that left event_type undefined instead of a string.","solutions":["Always set event_type to a valid EventType value when constructing events","Default the field at the boundary: event_type: raw.event_type ?? EventType.MEMORY_ADDED (when a sensible default exists)","Fix the upstream producer/deserializer so event_type is never dropped"],"exampleFix":"// before\nstream.publish({ payload }); // event_type undefined\n// after\nstream.publish({ event_type: EventType.MEMORY_ADDED, payload });","handlingStrategy":"validation","validationCode":"if (event.event_type === undefined) {\n  throw new Error(\"cannot publish event without event_type\");\n}\nstream.publish(event);","typeGuard":"function hasEventType(event: Partial<StreamEvent>): event is StreamEvent & { event_type: string } {\n  return typeof event.event_type === \"string\";\n}","tryCatchPattern":"try {\n  stream.publish(event);\n} catch (err) {\n  if (err instanceof TypeError && err.message === \"event_type is required\") {\n    logger.error(\"event missing event_type\", { keys: Object.keys(event) });\n  }\n  throw err;\n}","preventionTips":["Make event_type mandatory in your event-builder helpers","Default event_type at deserialization boundaries","Type event payloads so TS flags objects missing event_type"],"tags":["typeerror","validation","streaming"],"backgroundTag":"missing-required-field","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}