siyuan-note/siyuan · error
globalThis.siyuan.event is not an object
Error message
globalThis.siyuan.event is not an object
What it means
dispatchEvent converts the resolved siyuan.event value to a goja object via ToObject and requires a non-nil result. If ToObject yields nil (the value cannot be represented as an object), this error is returned, as the event hub's handler could not be located.
Solutions
- Inspect what siyuan.event currently holds in the plugin runtime
- Restore the standard event hub by re-running EnableSiyuanModule on a fresh runtime
- Prevent plugin code from reassigning globalThis.siyuan.event
- Verify the injected event hub is created with rt.NewObject() and has a handler function
Example fix
// before
rt.Set("siyuan", map[string]any{"event": 42}) // not convertible
// after
siyuan, _ := rt.NewObject()
event, _ := rt.NewObject()
siyuan.Set("event", event) Defensive patterns
Strategy: type-guard
Validate before calling
v, _ := getJsContextValue(rt, []any{"siyuan", "event"})
if _, ok := v.(*goja.Object); !ok && (v == nil || goja.IsUndefined(v) || goja.IsNull(v)) {
return fmt.Errorf("siyuan.event must be an object")
} Type guard
func isEventObject(v goja.Value) bool {
return v != nil && !goja.IsUndefined(v) && !goja.IsNull(v) && v.ToObject(nil) != nil
} Try / catch
if err := dispatchEvent(p, rt, name, data); err != nil {
log.Errorf("dispatch failed: %v", err)
return err
} Prevention
- Ensure the injected event hub is created with rt.NewObject()
- Do not let plugin scripts replace siyuan.event with primitives
- Re-run EnableSiyuanModule on a fresh runtime if the hub is corrupted
When it happens
Trigger: globalThis.siyuan.event holds a value that goja's ToObject cannot convert to an object (non-object exotic value in a corrupted runtime state); the property was replaced by something unusable before dispatch.
Common situations: Plugin scripts overwriting siyuan.event with a non-object primitive in a way that defeats earlier guards; runtime corruption after an interrupt; custom sandbox builds injecting a malformed event hub.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- globalThis.siyuan.event is
- globalThis.siyuan.event not found
- expected promise object, got %T
- failed to enable extend modules
- failed to inject global context
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/589fe95c958caf6c.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/plugin/sandbox.go:347
}
}()
event, err := getJsContextValue(rt, []any{"siyuan", "event"})
if err != nil {
return
}
if event == nil {
err = fmt.Errorf("globalThis.siyuan.event not found")
return
}
if goja.IsUndefined(event) || goja.IsNull(event) {
err = fmt.Errorf("globalThis.siyuan.event is %s", event.String())
return
}
eventObj := event.ToObject(rt)
if eventObj == nil {
err = fmt.Errorf("globalThis.siyuan.event is not an object")
return
}
handlerValue := eventObj.Get("handler")
handler, ok := goja.AssertFunction(handlerValue)
if !ok {
return
}
eventJs := rt.ToValue(e)
invokeResult, invokeErr := handler(event, eventJs)
if invokeErr != nil {
err = invokeErr
return
}
async = isJsPromise(invokeResult)
returnView on GitHub (pinned to 9f775e8a12)