siyuan-note/siyuan · error

invalid event object

Error message

invalid event object

What it means

Panicked when the SSE port.send() first argument is null/undefined OR is a value that cannot be turned into an object (ToObject returns nil). Distinct from missing-data: this means there is no usable event object at all to read fields from.

Source

Thrown at kernel/plugin/plugin.go:1403

					}

					if event := eventObj.Get("event"); goja.IsString(event) {
						e.Event = event.String()
					}

					if id := eventObj.Get("id"); goja.IsString(id) {
						e.Id = id.String()
					}

					if retry := eventObj.Get("retry"); goja.IsNumber(retry) {
						e.Retry = uint(retry.ToInteger())
					}

					events.In <- e
					return goja.Undefined()
				}
			}
			panic(rt.NewGoError(fmt.Errorf("invalid event object")))
		})

		port_close := rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
			doClose()
			return goja.Undefined()
		})

		lo.Must0(port.Set("onopen", goja.Null()))
		lo.Must0(port.Set("onclose", goja.Null()))

		lo.Must0(port.Set("send", port_send))
		lo.Must0(port.Set("close", port_close))

		lo.Must0(ObjectSeal(rt, port))

		lo.Must0(jsRequestObj.Set("port", port))

		invokeFunction(func(_ *goja.Runtime, result *CallResult) {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Always pass an event object: port.send({ data: '...' }).
  2. Use port.close() to end the stream instead of an empty send.
  3. Guard: if (!event) return; before port.send(event).

Example fix

// before
port.send(maybeEvent);

// after
if (maybeEvent && typeof maybeEvent === 'object' && 'data' in maybeEvent) {
  port.send(maybeEvent);
}
Defensive patterns

Strategy: type-guard

Validate before calling

function isValidEventObject(e: unknown): boolean { return !!e && typeof e === 'object'; }

Type guard

function isEventObject(e: unknown): e is { data: unknown; event?: string; id?: string; retry?: number } { return !!e && typeof e === 'object' && 'data' in (e as any); }

Try / catch

if (!isValidEventObject(event)) return; try { port.send(event); } catch (e) { /* ... */ }

Prevention

When it happens

Trigger: Calling port.send(), port.send(null), or port.send(undefined); or passing a primitive (number/string) where an event object is expected.

Common situations: Forwarding an optional event variable that is sometimes undefined, or calling send with no args to 'ping' the stream.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/4017554ae1d80700. Report an issue: GitHub.