{"record":{"id":"589fe95c958caf6c","repo":"siyuan-note/siyuan","slug":"globalthis-siyuan-event-is-not-an-object","errorCode":null,"errorMessage":"globalThis.siyuan.event is not an object","messagePattern":"globalThis\\.siyuan\\.event is not an object","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":347,"sourceCode":"\t\t}\n\t}()\n\n\tevent, err := getJsContextValue(rt, []any{\"siyuan\", \"event\"})\n\tif err != nil {\n\t\treturn\n\t}\n\tif event == nil {\n\t\terr = fmt.Errorf(\"globalThis.siyuan.event not found\")\n\t\treturn\n\t}\n\tif goja.IsUndefined(event) || goja.IsNull(event) {\n\t\terr = fmt.Errorf(\"globalThis.siyuan.event is %s\", event.String())\n\t\treturn\n\t}\n\n\teventObj := event.ToObject(rt)\n\tif eventObj == nil {\n\t\terr = fmt.Errorf(\"globalThis.siyuan.event is not an object\")\n\t\treturn\n\t}\n\n\thandlerValue := eventObj.Get(\"handler\")\n\thandler, ok := goja.AssertFunction(handlerValue)\n\tif !ok {\n\t\treturn\n\t}\n\n\teventJs := rt.ToValue(e)\n\tinvokeResult, invokeErr := handler(event, eventJs)\n\tif invokeErr != nil {\n\t\terr = invokeErr\n\t\treturn\n\t}\n\n\tasync = isJsPromise(invokeResult)\n\treturn","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/sandbox.go#L329-L365","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nrt.Set(\"siyuan\", map[string]any{\"event\": 42}) // not convertible\n// after\nsiyuan, _ := rt.NewObject()\nevent, _ := rt.NewObject()\nsiyuan.Set(\"event\", event)","handlingStrategy":"type-guard","validationCode":"v, _ := getJsContextValue(rt, []any{\"siyuan\", \"event\"})\nif _, ok := v.(*goja.Object); !ok && (v == nil || goja.IsUndefined(v) || goja.IsNull(v)) {\n    return fmt.Errorf(\"siyuan.event must be an object\")\n}","typeGuard":"func isEventObject(v goja.Value) bool {\n    return v != nil && !goja.IsUndefined(v) && !goja.IsNull(v) && v.ToObject(nil) != nil\n}","tryCatchPattern":"if err := dispatchEvent(p, rt, name, data); err != nil {\n    log.Errorf(\"dispatch failed: %v\", err)\n    return err\n}","preventionTips":["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"],"tags":["goja","plugin-sandbox","events"],"backgroundTag":"type-mismatch","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}