{"record":{"id":"faed84e0c4f08e4b","repo":"siyuan-note/siyuan","slug":"injectserver-v","errorCode":null,"errorMessage":"injectServer: %v","messagePattern":"injectServer: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_server.go","lineNumber":30,"sourceCode":"// GNU Affero General Public License for more details.\n//\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)\n\n// injectServer adds siyuan.server to the goja context.\nfunc injectServer(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(\"injectServer: %v\", r)\n\t\t}\n\t}()\n\n\thttp := rt.NewObject()\n\tws := rt.NewObject()\n\tes := rt.NewObject()\n\n\tlo.Must0(http.Set(\"handler\", goja.Null()))\n\tlo.Must0(ws.Set(\"handler\", goja.Null()))\n\tlo.Must0(es.Set(\"handler\", goja.Null()))\n\n\tlo.Must0(ObjectSeal(rt, http))\n\tlo.Must0(ObjectSeal(rt, ws))\n\tlo.Must0(ObjectSeal(rt, es))\n\n\tprivate := rt.NewObject()\n\n\tlo.Must0(private.Set(string(RequestTypeHTTP), http))","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_server.go#L12-L48","documentation":"injectServer adds the siyuan.server (http/ws/es) API surface to the plugin's goja runtime. Any panic during that setup is recovered and reported as 'injectServer: %v'. The plugin fails to load with the server API available; it is an initialization-time failure, not a per-request error.","triggerScenarios":"Panic while creating or registering the http/ws/es objects during plugin runtime bootstrap.","commonSituations":"Kernel-side server wiring unavailable or misconfigured at plugin load; property registration conflicts on the siyuan object; a kernel bug introduced in a plugin API update.","solutions":["Inspect the wrapped cause (%v) and kernel logs at plugin load time","Restart the kernel and reload the plugin to retry injection","Update kernel and plugin to compatible versions","If reproducible, report with the panic cause from the logs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { useServerApi() } catch (e) { if (String(e.message).startsWith('injectServer:')) { /* server API unavailable */ } throw e }","preventionTips":["Verify plugin API surface availability before use (feature-detect siyuan.server)","Update kernel/plugin together","Watch kernel logs during plugin load for injection panics"],"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"}