siyuan-note/siyuan · error
failed to inject global context: %v
Error message
failed to inject global context: %v
What it means
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.
Source
Thrown at kernel/plugin/sandbox.go:101
registry := require.NewRegistry()
registry.Enable(rt)
registry.RegisterNativeModule(
console.ModuleName,
console.RequireWithPrinter(&Printer{name: p.Name}),
)
url.Enable(rt)
buffer.Enable(rt)
console.Enable(rt)
return
}
// EnableSiyuanModule injects all siyuan.* APIs into the plugin's goja global context.
func EnableSiyuanModule(p *KernelPlugin, rt *goja.Runtime) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("failed to inject global context: %v", r)
}
}()
siyuan := rt.NewObject()
lo.Must0(injectPlugin(p, rt, siyuan))
lo.Must0(injectEvent(p, rt, siyuan))
lo.Must0(injectLogger(p, rt, siyuan))
lo.Must0(injectStorage(p, rt, siyuan))
lo.Must0(injectRpc(p, rt, siyuan))
lo.Must0(injectAgent(p, rt, siyuan))
lo.Must0(injectClient(p, rt, siyuan))
lo.Must0(injectServer(p, rt, siyuan))
lo.Must0(injectSecretsVars(p, rt, siyuan))
lo.Must0(ObjectFreeze(rt, siyuan))
lo.Must0(rt.GlobalObject().Set("siyuan", siyuan))View on GitHub (pinned to 251596fc0d)
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.
Defensive patterns
Strategy: try-catch
Try / catch
// load-time; cannot retry meaningfully from plugin JS
catchLoadError(e) { if (/inject global context/.test(String(e))) report(e); } Prevention
- Check the kernel log for which inject* step panicked.
- Update kernel and plugin together.
- Reproduce with a minimal plugin and report.
When it happens
Trigger: 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).
Common situations: 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).
Related errors
- failed to enable extend modules: %v
- ObjectSetDataMethods: %v
- panic during siyuan.storage.list: %v
- failed to convert request value to object
- path %v: value is nil
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/74e9f072cf23048f.
Report an issue: GitHub.