{"record":{"id":"708553bdec98d8cd","repo":"siyuan-note/siyuan","slug":"injectlogger-v","errorCode":null,"errorMessage":"injectLogger: %v","messagePattern":"injectLogger: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_logger.go","lineNumber":56,"sourceCode":"}\n\nfunc (p *Printer) Error(s string) {\n\tgo print(p.name, s, logging.LogErrorf)\n}\n\n// print logs the message line by line with the plugin name as prefix, using the provided log function.\nfunc print(name, s string, logf func(format string, v ...any)) {\n\trows := strings.SplitSeq(s, \"\\n\")\n\tfor row := range rows {\n\t\tlogf(\"[plugin:%s] %s\", name, row)\n\t}\n}\n\n// injectLogger adds siyuan.logger to the goja context.\nfunc injectLogger(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(\"injectLogger: %v\", r)\n\t\t}\n\t}()\n\n\tlogger := rt.NewObject()\n\n\tlo.Must0(logger.Set(\"trace\", rt.ToValue(loggerWrapper(p, logging.LogTracef))))\n\tlo.Must0(logger.Set(\"debug\", rt.ToValue(loggerWrapper(p, logging.LogDebugf))))\n\tlo.Must0(logger.Set(\"info\", rt.ToValue(loggerWrapper(p, logging.LogInfof))))\n\tlo.Must0(logger.Set(\"warn\", rt.ToValue(loggerWrapper(p, logging.LogWarnf))))\n\tlo.Must0(logger.Set(\"error\", rt.ToValue(loggerWrapper(p, logging.LogErrorf))))\n\n\tlo.Must0(ObjectFreeze(rt, logger))\n\n\tlo.Must0(siyuan.Set(\"logger\", logger))\n\treturn\n}\n\n// loggerWrapper returns a JS-callable function that logs a message at the given level.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/plugin/api_logger.go#L38-L74","documentation":"injectLogger installs the siyuan.logger object into the plugin's goja runtime; this error wraps any panic raised while creating or registering the logger API (rt.NewObject, logger.Set of trace/debug/info/... wrappers). Like injectEvent, it indicates an internal fault during plugin runtime bootstrap rather than a plugin-code mistake, and typically aborts plugin initialization.","triggerScenarios":"Panic inside the logger object construction or wrapper registration during plugin injection — e.g. a broken goja runtime, concurrent runtime teardown, or a kernel-side regression in the logger setup path.","commonSituations":"Plugin worker shutting down while injection is in progress; kernel/plugin version mismatch introducing setup incompatibility; corrupted plugin load sequence after a prior injection failure.","solutions":["Restart the kernel so the plugin runtime is rebuilt cleanly","Update kernel and plugins to compatible versions","Inspect kernel logs for the wrapped panic detail (%v) to find the failing logger registration","Isolate by disabling plugins one by one to find one corrupting the worker"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { startPluginRuntime(); } catch (e) { if (String(e).startsWith(\"injectLogger:\")) { restartKernelPluginHost(); } else { throw e; } }","preventionTips":["Keep kernel updated — this is an internal bootstrap fault","Avoid racing worker termination with injection","Use kernel logs showing the wrapped panic value to diagnose","Test plugin load after upgrades to catch bootstrap regressions early"],"tags":["panic","plugin-api","goja","logger","initialization"],"backgroundTag":"internal-invariant-violation","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}