{"record":{"id":"bc6785656b9db158","repo":"siyuan-note/siyuan","slug":"injectclient-v","errorCode":null,"errorMessage":"injectClient: %v","messagePattern":"injectClient: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_client.go","lineNumber":42,"sourceCode":"\t\"net/http\"\n\t\"strings\"\n\t\"sync\"\n\t\"sync/atomic\"\n\n\t\"github.com/dop251/goja\"\n\t\"github.com/lxzan/gws\"\n\tsse \"github.com/r3labs/sse/v2\"\n\t\"github.com/samber/lo\"\n\t\"github.com/siyuan-note/logging\"\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\n// injectClient adds siyuan.server to the goja context.\nfunc injectClient(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"injectClient: %v\", r)\n\t\t}\n\t}()\n\n\tclient := rt.NewObject()\n\n\tlo.Must0(client.Set(\"fetch\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\tvar argErr error\n\t\tvar path string\n\t\tmethod := \"GET\"\n\t\theaders := map[string]string{}\n\t\tvar bodyString *string\n\t\tvar bodyBytes *[]byte\n\n\t\tif goja.IsString(call.Argument(0)) {\n\t\t\tpath = call.Argument(0).String()\n\t\t} else {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_client.go#L24-L60","documentation":"injectClient builds the siyuan.client object inside the plugin's goja runtime and attaches an HTTP fetch bridge to the kernel. The whole setup runs under a recover() guard; any panic during object creation or function binding is converted into this error. It indicates an unexpected runtime failure while wiring the client API, not a normal usage error.","triggerScenarios":"A panic inside rt.NewObject(), client.Set(...), or the ToValue wrappers during plugin runtime initialization — e.g. a corrupted runtime, out-of-memory, or a bug in a native callback registered on the client object.","commonSituations":"Kernel-side bugs or resource exhaustion during plugin boot; a plugin runtime being torn down while injectClient is still running; rarely hit by plugin authors directly.","solutions":["Retry loading the plugin; the failure is often transient or runtime-related","Check kernel logs for the full recovered panic value and stack","Verify plugin runtime/memory settings and reduce plugin concurrency if OOM is suspected","Report the panic value with plugin name and version if reproducible"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await loadPlugin(p);\n} catch (e) {\n  if (String(e).startsWith(\"injectClient:\")) {\n    logAndRetry(p); // transient runtime failure; report if persistent\n  }\n}","preventionTips":["Keep plugin count and runtime memory within reasonable limits","Update the kernel to the latest version where runtime panics are fixed","Report reproducible injectClient panics with logs"],"tags":["plugin","goja","panic","runtime"],"backgroundTag":"internal-invariant-violation","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"}