siyuan-note/siyuan · error
injectStorage: %v
Error message
injectStorage: %v
What it means
injectStorage registers the siyuan.storage.* file CRUD API into a kernel plugin's goja runtime. Any panic during this registration (lo.Must0 failing on Object.Set/ObjectFreeze, etc.) is recovered and returned as "injectStorage: %v", failing the plugin load. It signals a kernel-side injection failure, not a plugin script error.
Source
Thrown at kernel/plugin/api_storage.go:36
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/dop251/goja"
"github.com/samber/lo"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/util"
)
// injectStorage adds siyuan.storage.* methods for scoped file CRUD.
func injectStorage(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("injectStorage: %v", r)
}
}()
resolvePath := func(relPath string) (abs string, err error) {
abs = filepath.Join(p.storageDir, filepath.Clean(relPath))
if !(abs == p.storageDir || strings.HasPrefix(abs, p.storageDir+string(filepath.Separator))) {
err = fmt.Errorf("siyuan.storage: path traversal not allowed")
}
return
}
watcher := rt.NewObject()
// siyuan.storage.watcher.add(path) -> Promise<void>
lo.Must0(watcher.Set("add", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
promise, resolve, reject := rt.NewPromise()
var argErr errorView on GitHub (pinned to 8641553a1f)
Solutions
- Read the wrapped panic message in the log to find the underlying cause
- Restart SiYuan; broken runtime state during injection is usually transient
- Upgrade SiYuan to the latest version to pick up fixes in the plugin subsystem
- If it reproduces, isolate by disabling plugins and report the issue with logs
Defensive patterns
Strategy: try-catch
Try / catch
// Kernel-side Go code loading the plugin
if err := injectStorage(p, rt, siyuan); err != nil {
return fmt.Errorf("plugin %s load failed: %w", p.Name, err)
} Prevention
- Restart SiYuan before deep debugging; the failure is often transient runtime state
- Update SiYuan to the latest version to get injection fixes
- Include full kernel logs when filing the issue
When it happens
Trigger: A panic inside injectStorage: one of the many lo.Must0 calls returns an error (e.g. setting a property fails because the object is sealed or the goja runtime is corrupted), or an unexpected panic occurs while wiring watcher/get/put/remove/list methods.
Common situations: Seen during plugin loading at SiYuan startup or when enabling a kernel plugin; typically caused by internal runtime state problems rather than anything the plugin author did.
Related errors
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/5bbe7a07df3f8d8c.
Report an issue: GitHub.