{"record":{"id":"0f7a4d010e12369a","repo":"siyuan-note/siyuan","slug":"enableextendmodules-v","errorCode":null,"errorMessage":"EnableExtendModules: %v","messagePattern":"EnableExtendModules: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/plugin.go","lineNumber":200,"sourceCode":"}\n\n// InitRuntime initializes the goja runtime and evaluates kernel.js.\nfunc (p *KernelPlugin) InitRuntime() (err error) {\n\tp.runtime = eventloop.NewEventLoop(eventloop.EnableConsole(true))\n\tp.worker.Start(p.runtime)\n\n\tp.runtime.Run(func(rt *goja.Runtime) {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\terr = fmt.Errorf(\"goja panic during event loop run: %v\", r)\n\t\t\t}\n\t\t}()\n\n\t\t// Use JSON struct tags for field name mapping, with fallback to original names if \"json\" tag is absent.\n\t\trt.SetFieldNameMapper(goja.TagFieldNameMapper(\"json\", true))\n\n\t\tif enableErr := EnableExtendModules(p, rt); enableErr != nil {\n\t\t\terr = fmt.Errorf(\"EnableExtendModules: %v\", enableErr)\n\t\t\treturn\n\t\t}\n\n\t\tif enableErr := EnableSiyuanModule(p, rt); enableErr != nil {\n\t\t\terr = fmt.Errorf(\"EnableSiyuanModule: %v\", enableErr)\n\t\t\treturn\n\t\t}\n\n\t\tif _, runErr := rt.RunScript(p.file, p.Kernel.JS); runErr != nil {\n\t\t\terr = fmt.Errorf(\"RunScript: %v\", runErr)\n\t\t\treturn\n\t\t}\n\t})\n\tp.runtime.Start()\n\treturn\n}\n\n// Eval evaluates JavaScript code in the plugin's goja runtime, returning the result or error.","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/plugin.go#L182-L218","documentation":"When initializing a plugin's goja runtime, the kernel first registers the extend modules (RPC, sockets, etc.) via `EnableExtendModules`. If that registration returns an error, it is wrapped as `EnableExtendModules: %v` and plugin startup fails. It means one of the extended API surfaces could not be installed into the plugin's JS runtime.","triggerScenarios":"Any error returned by EnableExtendModules during InitRuntime — e.g. lo.Must assertions on module property registration failing, or a sub-registration (RPC method table, socket API) returning an error.","commonSituations":"Kernel-side bugs after an upgrade where module registration code asserts on frozen objects, or a plugin started twice concurrently so runtime state is inconsistent.","solutions":["Inspect the wrapped inner error in the log for the specific module that failed to enable","Restart the plugin to rule out a duplicate-start race","Update SiYuan kernel if the inner error points at module registration code","Report with plugin name and full error if reproducible"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := plugin.Start(); err != nil && strings.Contains(err.Error(), \"EnableExtendModules\") { // disable plugin and retry once after restart }","preventionTips":["Restart the kernel after upgrading SiYuan before enabling plugins","Do not start the same plugin concurrently","Check kernel logs for the wrapped inner module error","Report persistent failures with the inner error text"],"tags":["plugin-lifecycle","goja","module-registration"],"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"}