siyuan-note/siyuan · error
injectSecretsVars: %v
Error message
injectSecretsVars: %v
What it means
injectSecretsVars installs siyuan.secrets/siyuan.vars resolve helpers into the plugin's goja runtime. Panics during this setup are recovered and wrapped as 'injectSecretsVars: %v', aborting plugin load.
Source
Thrown at kernel/plugin/api_secrets_vars.go:34
package plugin
import (
"fmt"
"github.com/dop251/goja"
"github.com/samber/lo"
"github.com/siyuan-note/siyuan/kernel/model"
)
// injectSecretsVars adds siyuan.secrets and siyuan.vars to the plugin JS sandbox.
// siyuan.secrets.resolve(tpl) 仅替换模板里的 {{secrets.NAME}} 占位符,
// siyuan.vars.resolve(tpl) 仅替换 {{vars.NAME}}。两者各自只返回替换后的字符串,
// 不向插件暴露密钥/变量清单。同步执行(纯内存操作,无 I/O)。
func injectSecretsVars(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("injectSecretsVars: %v", r)
}
}()
secrets := rt.NewObject()
lo.Must0(secrets.Set("resolve", rt.ToValue(makeResolver(func(tpl string) string {
return model.Conf.Secrets.Resolve(tpl)
}))))
lo.Must0(siyuan.Set("secrets", secrets))
vars := rt.NewObject()
lo.Must0(vars.Set("resolve", rt.ToValue(makeResolver(func(tpl string) string {
return model.Conf.Variables.Resolve(tpl)
}))))
lo.Must0(siyuan.Set("vars", vars))
return
}
View on GitHub (pinned to 8641553a1f)
Solutions
- Read the wrapped %v detail to find the panicking operation
- Verify model.Conf.Secrets / Vars resolvers are initialized before injection
- Check that makeResolver and its Set assertions succeed without duplicates
- If deterministic, debug kernel/plugin/api_secrets_vars.go
Defensive patterns
Strategy: try-catch
Validate before calling
if (!modelConf || !modelConf.Secrets || !modelConf.Vars) {
throw new Error("secrets/vars configuration missing before injection");
} Try / catch
try {
await loadPlugin(plugin);
} catch (e) {
if (String(e).startsWith("injectSecretsVars:")) {
console.error("secrets/vars injection failed:", e);
}
} Prevention
- Ensure the secrets/vars resolvers are initialized before plugin load
- Do not modify runtime state concurrently with injection
- Check the %v detail for the underlying panic
When it happens
Trigger: A panic occurs while creating the secrets/vars objects or their resolve method values in the goja runtime — e.g. runtime in an invalid state or a lo.Must0 assertion failing.
Common situations: Plugin bootstrap failure caused by kernel-side runtime issues rather than plugin-author mistakes; often environment-specific (corrupt runtime, version mismatch).
Related errors
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/d334670a338dfdb1.
Report an issue: GitHub.