can1357/oh-my-pi · error · TypeError

event_type is required

Error message

event_type is required

What it means

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.

Source

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

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

export type MemoryEventDict = {
	event_type: string;
	memory_id: string;
	timestamp: string;
	session_id?: string | null;
	content?: string | null;
	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 ||

View on GitHub (pinned to 9690622007)

Solutions

  1. Always set event_type to a valid EventType value when constructing events
  2. Default the field at the boundary: event_type: raw.event_type ?? EventType.MEMORY_ADDED (when a sensible default exists)
  3. Fix the upstream producer/deserializer so event_type is never dropped

Example fix

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

Strategy: validation

Validate before calling

if (event.event_type === undefined) {
  throw new Error("cannot publish event without event_type");
}
stream.publish(event);

Type guard

function hasEventType(event: Partial<StreamEvent>): event is StreamEvent & { event_type: string } {
  return typeof event.event_type === "string";
}

Try / catch

try {
  stream.publish(event);
} catch (err) {
  if (err instanceof TypeError && err.message === "event_type is required") {
    logger.error("event missing event_type", { keys: Object.keys(event) });
  }
  throw err;
}

Prevention

When it happens

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

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

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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