{"record":{"id":"d350b4bf44bf83b3","repo":"can1357/oh-my-pi","slug":"unknown-event-type-value","errorCode":null,"errorMessage":"Unknown event type: ${value}","messagePattern":"Unknown event type: (.+?)","errorType":"validation","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/streaming.ts","lineNumber":82,"sourceCode":"\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 ||\n\t\ttypeof value === \"string\" ||\n\t\ttypeof value === \"number\" ||\n\t\ttypeof value === \"bigint\" ||\n\t\ttypeof value === \"boolean\" ||\n\t\t(ArrayBuffer.isView(value) && !(value instanceof DataView))\n\t);\n}\n\nexport class MemoryEvent {\n\treadonly eventType: EventType;\n\treadonly memoryId: string;","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/streaming.ts#L64-L100","documentation":"After checking the exact enum values and enum-key aliases, normalizeEventType throws a RangeError for any other string, embedding the offending value. Only the EventType enum members (by value or by key name) are accepted.","triggerScenarios":"Passing \"memory_added\" (wrong case), \"deleted\" (not a member), or a free-form string to the event constructor or eventType accessor; enum key lookup also fails so nothing matches.","commonSituations":"Case-sensitivity mistakes (lowercase vs the enum's uppercase names); events arriving from external systems with a different event taxonomy; enum renamed/removed in a newer version while old producers still emit the old name.","solutions":["Use EventType enum members for values instead of hand-written strings","Check the enum (Object.values(EventType)) for the exact accepted strings and match casing","Add a mapping step at the boundary translating external event names to EventType before publishing"],"exampleFix":"// before\nstream.publish({ event_type: \"memory added\", payload });\n// after\nstream.publish({ event_type: EventType.MEMORY_ADDED, payload });","handlingStrategy":"validation","validationCode":"import { EventType } from \"...\";\nconst valid = new Set<string>(Object.values(EventType));\nif (!valid.has(rawType) && !(rawType in EventType)) {\n  throw new Error(`unsupported event type: ${rawType}`);\n}\nstream.publish({ event_type: rawType as EventType, payload });","typeGuard":"function isEventType(value: string): value is EventType {\n  return value in EventType || Object.values(EventType).includes(value as EventType);\n}","tryCatchPattern":"try {\n  stream.publish({ event_type: rawType, payload });\n} catch (err) {\n  if (err instanceof RangeError && err.message.startsWith(\"Unknown event type\")) {\n    logger.warn(\"mapping unknown event type to MEMORY_ADDED\", { rawType });\n    stream.publish({ event_type: EventType.MEMORY_ADDED, payload });\n    return;\n  }\n  throw err;\n}","preventionTips":["Always pass EventType enum members, not hand-written strings","Mind case sensitivity — enum values/keys are uppercase","Add a mapping layer for external event taxonomies and update it on library upgrades"],"tags":["validation","enum","streaming"],"backgroundTag":"invalid-enum-value","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}