{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/api_secrets_vars.go#L16-L52","documentation":"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.","triggerScenarios":"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.","commonSituations":"Plugin bootstrap failure caused by kernel-side runtime issues rather than plugin-author mistakes; often environment-specific (corrupt runtime, version mismatch).","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!modelConf || !modelConf.Secrets || !modelConf.Vars) {\n    throw new Error(\"secrets/vars configuration missing before injection\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    await loadPlugin(plugin);\n} catch (e) {\n    if (String(e).startsWith(\"injectSecretsVars:\")) {\n        console.error(\"secrets/vars injection failed:\", e);\n    }\n}","preventionTips":["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"],"tags":["goja","plugin","secrets","panic-recovery"],"backgroundTag":"module-init-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}