{"record":{"id":"74e9f072cf23048f","repo":"siyuan-note/siyuan","slug":"failed-to-inject-global-context-v","errorCode":null,"errorMessage":"failed to inject global context: %v","messagePattern":"failed to inject global context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/sandbox.go","lineNumber":101,"sourceCode":"\tregistry := require.NewRegistry()\n\n\tregistry.Enable(rt)\n\tregistry.RegisterNativeModule(\n\t\tconsole.ModuleName,\n\t\tconsole.RequireWithPrinter(&Printer{name: p.Name}),\n\t)\n\n\turl.Enable(rt)\n\tbuffer.Enable(rt)\n\tconsole.Enable(rt)\n\treturn\n}\n\n// EnableSiyuanModule injects all siyuan.* APIs into the plugin's goja global context.\nfunc EnableSiyuanModule(p *KernelPlugin, rt *goja.Runtime) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"failed to inject global context: %v\", r)\n\t\t}\n\t}()\n\n\tsiyuan := rt.NewObject()\n\n\tlo.Must0(injectPlugin(p, rt, siyuan))\n\tlo.Must0(injectEvent(p, rt, siyuan))\n\tlo.Must0(injectLogger(p, rt, siyuan))\n\tlo.Must0(injectStorage(p, rt, siyuan))\n\tlo.Must0(injectRpc(p, rt, siyuan))\n\tlo.Must0(injectAgent(p, rt, siyuan))\n\tlo.Must0(injectClient(p, rt, siyuan))\n\tlo.Must0(injectServer(p, rt, siyuan))\n\tlo.Must0(injectSecretsVars(p, rt, siyuan))\n\n\tlo.Must0(ObjectFreeze(rt, siyuan))\n\n\tlo.Must0(rt.GlobalObject().Set(\"siyuan\", siyuan))","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/plugin/sandbox.go#L83-L119","documentation":"A recovered panic from EnableSiyuanModule, which builds the global siyuan object by calling injectPlugin/injectEvent/injectLogger/injectStorage/injectRpc/injectAgent/injectClient/injectServer/injectSecretsVars and freezes it. Any panic during injection (a lo.Must0 that fails, a nil runtime field) is caught and wrapped here.","triggerScenarios":"A panic during siyuan.* API injection at plugin load, e.g. one of the inject* helpers hit lo.Must0 with an error because a sub-injection failed (e.g. injectStorage panicked and bubbled).","commonSituations":"Plugin fails to load entirely with this message in the kernel log. Usually points to a kernel bug or a half-initialized plugin context (e.g. storageDir not set).","solutions":["Read the full kernel log line to find which inject* step panicked (the inner error is in the panic value).","Update the kernel and plugin to compatible versions.","Reproduce with a minimal plugin to isolate which siyuan.* API triggers injection failure.","Report the inner panic to the issue tracker."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// load-time; cannot retry meaningfully from plugin JS\ncatchLoadError(e) { if (/inject global context/.test(String(e))) report(e); }","preventionTips":["Check the kernel log for which inject* step panicked.","Update kernel and plugin together.","Reproduce with a minimal plugin and report."],"tags":["plugin","sandbox","load","panic","internal-bug"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}