siyuan-note/siyuan · error
injectSecretsVars
Error message
injectSecretsVars: %v
What it means
injectSecretsVars registers siyuan.secrets/siyuan.vars resolvers into the goja runtime. Any panic during that injection (e.g. failure creating runtime objects or registering properties) is recovered and converted to 'injectSecretsVars: %v'. It indicates the plugin JS runtime could not be fully initialized with the secrets/vars API, not a problem with a specific resolve() call.
Solutions
- Read the wrapped %v cause in the error to identify the underlying panic
- Reload or re-enable the plugin so injection runs again on a fresh runtime
- Update the kernel/plugin to the latest version if injection panics reproducibly
- Check kernel logs around plugin load for the original panic stack
Defensive patterns
Strategy: try-catch
Try / catch
try { useSecretsApis() } catch (e) { if (String(e.message).startsWith('injectSecretsVars:')) { /* plugin runtime init failed; reload plugin */ } throw e } Prevention
- Keep kernel and plugin versions compatible
- Check kernel logs at plugin load for panics
- Reload plugins after kernel config changes to secrets/vars
When it happens
Trigger: A panic inside injectSecretsVars while setting up the resolver objects on the plugin's goja runtime during plugin load.
Common situations: Runtime in a broken state after earlier injection failures; conflicts registering siyuan.secrets/vars properties; kernel-side configuration objects (model.Conf.Secrets) misbehaving at plugin startup.
Related errors
- injectServer
- encrypted notebook lock callbacks are not initialized
- failed to run task on event loop
- initialize encrypted notebook document failed
- 26
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/d334670a338dfdb1.
Report an issue: GitHub.
Appendix: 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 9f775e8a12)