{"record":{"id":"81c00ad491628e7f","repo":"siyuan-note/siyuan","slug":"globalthis-siyuan-event-not-found","errorCode":null,"errorMessage":"globalThis.siyuan.event not found","messagePattern":"globalThis\\.siyuan\\.event not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":337,"sourceCode":"\t}\n\tvalue = cursor\n\treturn\n}\n\n// dispatchEvent calls the globalThis.siyuan.event.on hook with the given event object.\nfunc dispatchEvent(p *KernelPlugin, rt *goja.Runtime, e any) (async bool, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"goja panic during dispatchEvent: %v\", r)\n\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}","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/sandbox.go#L319-L355","documentation":"After resolving the path globalThis.siyuan.event via getJsContextValue, dispatchEvent checks whether the returned value is nil and throws this error if the property lookup yielded nothing. It means the plugin runtime does not expose a siyuan.event object at all, so kernel events cannot be delivered to the plugin.","triggerScenarios":"The plugin JS context has no siyuan.event defined — the plugin bundle did not initialize the SiYuan plugin API shims, or the property was deleted/never assigned before the kernel dispatches an event.","commonSituations":"A plugin built against an older plugin API that predates the event bus; a plugin whose entry script failed partway, leaving siyuan partially initialized; manual manipulation of globalThis.siyuan in plugin code.","solutions":["Ensure the plugin initializes globalThis.siyuan.event (with an on/addListener hook) during load, before any kernel event can fire","Rebuild/reinstall the plugin against the current SiYuan plugin API so the event shim is created by the runtime bootstrap","Check that the plugin's entry script completed without an earlier error that aborted siyuan initialization"],"exampleFix":"// before (plugin JS): no event object created\n// after\nwindow.siyuan = window.siyuan || {};\nsiyuan.event = siyuan.event || { on: (name, cb) => { listeners[name] = cb; } };","handlingStrategy":"validation","validationCode":"if (typeof siyuan === 'undefined' || !siyuan.event || typeof siyuan.event.on !== 'function') { throw new Error('plugin must initialize siyuan.event.on before use'); }","typeGuard":"const eventReady = (g) => g != null && g.siyuan != null && g.siyuan.event != null && typeof g.siyuan.event.on === 'function';","tryCatchPattern":"if err := dispatchEvent(p, rt, e); err != nil { if strings.Contains(err.Error(), \"not found\") { log.Warnf(\"plugin %s has no event hook: %v\", p.Name, err) } return }","preventionTips":["Initialize globalThis.siyuan.event synchronously at the very top of the plugin entry","Scaffold plugins from the current official template so the event shim is included","Add a self-check on load that fails fast when siyuan.event is absent"],"tags":["goja","plugins","events","missing-api"],"backgroundTag":"entity-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}