{"record":{"id":"5fcbc450d623809b","repo":"siyuan-note/siyuan","slug":"injectplugin-v","errorCode":null,"errorMessage":"injectPlugin: %v","messagePattern":"injectPlugin: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_plugin.go","lineNumber":31,"sourceCode":"//\n// You should have received a copy of the GNU Affero General Public License\n// along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\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/bazaar\"\n)\n\n// injectPlugin adds siyuan.plugin to the goja context.\nfunc injectPlugin(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(\"injectPlugin: %v\", r)\n\t\t}\n\t}()\n\n\tlifecycle := rt.NewObject()\n\tlo.Must0(lifecycle.Set(\"onload\", goja.Null()))\n\tlo.Must0(lifecycle.Set(\"onrunning\", goja.Null()))\n\tlo.Must0(lifecycle.Set(\"onunload\", goja.Null()))\n\tlo.Must0(ObjectSeal(rt, lifecycle))\n\n\tplugin := rt.NewObject()\n\tlo.Must0(plugin.Set(\"name\", p.Name))\n\tlo.Must0(plugin.Set(\"version\", p.Version))\n\tlo.Must0(plugin.Set(\"displayName\", p.DisplayName))\n\tlo.Must0(plugin.Set(\"platform\", bazaar.GetCurrentBackend()))\n\tlo.Must0(plugin.Set(\"i18n\", p.I18n))\n\tlo.Must0(plugin.Set(\"lifecycle\", lifecycle))\n\tlo.Must0(ObjectFreeze(rt, plugin))\n","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_plugin.go#L13-L49","documentation":"injectPlugin installs the siyuan.plugin object (lifecycle hooks such as onload/onrunning) into the plugin's goja runtime. A panic during that installation is recovered and returned as this error, meaning the plugin lifecycle API could not be registered.","triggerScenarios":"A panic inside rt.NewObject() or the lifecycle/property Set calls while the kernel bootstraps the plugin runtime.","commonSituations":"Kernel-side defects during plugin bootstrap; encountered at plugin load time, before plugin JS runs.","solutions":["Read the wrapped %v detail and report it to the maintainers with the plugin name","Update the kernel to the latest version","Retry loading the plugin to rule out a transient failure","Disable other plugins to rule out shared-state interference"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await loadPlugin(p);\n} catch (e) {\n  if (String(e.message).startsWith('injectPlugin:')) {\n    console.error('Plugin lifecycle API failed to install:', e.message);\n  }\n}","preventionTips":["Keep the kernel binary current","Feature-check siyuan.plugin before registering lifecycle hooks","Capture the full error text for upstream bug reports"],"tags":["goja","plugin-init","panic","lifecycle"],"backgroundTag":"internal-invariant-violation","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"}