can1357/oh-my-pi · error · RangeError

Unknown event type: ${value}

Error message

Unknown event type: ${value}

What it means

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.

Source

Thrown at packages/mnemopi/src/core/streaming.ts:82

	source?: string | null;
	importance?: number | null;
	metadata?: Record<string, unknown> | null;
	delta?: Record<string, unknown> | null;
};

function normalizeEventType(value: string | undefined): EventType {
	if (value === undefined) throw new TypeError("event_type is required");
	switch (value) {
		case EventType.MEMORY_ADDED:
		case EventType.MEMORY_RECALLED:
		case EventType.MEMORY_INVALIDATED:
		case EventType.MEMORY_CONSOLIDATED:
		case EventType.MEMORY_UPDATED:
			return value;
		default: {
			const mapped = EventType[value as keyof typeof EventType];
			if (mapped !== undefined) return mapped;
			throw new RangeError(`Unknown event type: ${value}`);
		}
	}
}

function isSqlQueryBinding(value: unknown): value is SQLQueryBindings {
	return (
		value === null ||
		typeof value === "string" ||
		typeof value === "number" ||
		typeof value === "bigint" ||
		typeof value === "boolean" ||
		(ArrayBuffer.isView(value) && !(value instanceof DataView))
	);
}

export class MemoryEvent {
	readonly eventType: EventType;
	readonly memoryId: string;

View on GitHub (pinned to 9690622007)

Solutions

  1. Use EventType enum members for values instead of hand-written strings
  2. Check the enum (Object.values(EventType)) for the exact accepted strings and match casing
  3. Add a mapping step at the boundary translating external event names to EventType before publishing

Example fix

// before
stream.publish({ event_type: "memory added", payload });
// after
stream.publish({ event_type: EventType.MEMORY_ADDED, payload });
Defensive patterns

Strategy: validation

Validate before calling

import { EventType } from "...";
const valid = new Set<string>(Object.values(EventType));
if (!valid.has(rawType) && !(rawType in EventType)) {
  throw new Error(`unsupported event type: ${rawType}`);
}
stream.publish({ event_type: rawType as EventType, payload });

Type guard

function isEventType(value: string): value is EventType {
  return value in EventType || Object.values(EventType).includes(value as EventType);
}

Try / catch

try {
  stream.publish({ event_type: rawType, payload });
} catch (err) {
  if (err instanceof RangeError && err.message.startsWith("Unknown event type")) {
    logger.warn("mapping unknown event type to MEMORY_ADDED", { rawType });
    stream.publish({ event_type: EventType.MEMORY_ADDED, payload });
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/d350b4bf44bf83b3. Report an issue: GitHub.