{"record":{"id":"d334670a338dfdb1","repo":"siyuan-note/siyuan","slug":"injectsecretsvars-v","errorCode":null,"errorMessage":"injectSecretsVars: %v","messagePattern":"injectSecretsVars: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_secrets_vars.go","lineNumber":34,"sourceCode":"\npackage plugin\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/dop251/goja\"\n\t\"github.com/samber/lo\"\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n)\n\n// injectSecretsVars adds siyuan.secrets and siyuan.vars to the plugin JS sandbox.\n// siyuan.secrets.resolve(tpl) 仅替换模板里的 {{secrets.NAME}} 占位符，\n// siyuan.vars.resolve(tpl) 仅替换 {{vars.NAME}}。两者各自只返回替换后的字符串，\n// 不向插件暴露密钥/变量清单。同步执行（纯内存操作，无 I/O）。\nfunc injectSecretsVars(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(\"injectSecretsVars: %v\", r)\n\t\t}\n\t}()\n\n\tsecrets := rt.NewObject()\n\tlo.Must0(secrets.Set(\"resolve\", rt.ToValue(makeResolver(func(tpl string) string {\n\t\treturn model.Conf.Secrets.Resolve(tpl)\n\t}))))\n\tlo.Must0(siyuan.Set(\"secrets\", secrets))\n\n\tvars := rt.NewObject()\n\tlo.Must0(vars.Set(\"resolve\", rt.ToValue(makeResolver(func(tpl string) string {\n\t\treturn model.Conf.Variables.Resolve(tpl)\n\t}))))\n\tlo.Must0(siyuan.Set(\"vars\", vars))\n\n\treturn\n}\n","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_secrets_vars.go#L16-L52","documentation":"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.","triggerScenarios":"A panic inside injectSecretsVars while setting up the resolver objects on the plugin's goja runtime during plugin load.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { useSecretsApis() } catch (e) { if (String(e.message).startsWith('injectSecretsVars:')) { /* plugin runtime init failed; reload plugin */ } throw e }","preventionTips":["Keep kernel and plugin versions compatible","Check kernel logs at plugin load for panics","Reload plugins after kernel config changes to secrets/vars"],"tags":["go","plugin-runtime","panic-recovery","initialization"],"backgroundTag":"module-init-failed","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"}