{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_logger.go#L38-L74","documentation":"injectLogger registers siyuan.logger (trace/debug/info/warn/error wrappers bound to the kernel logging package) into the plugin's goja runtime. Any Go panic during that registration is recovered and reported as this error, meaning the logger API could not be installed for the plugin.","triggerScenarios":"A panic inside rt.NewObject(), logger.Set(...) calls, or loggerWrapper binding failures while bootstrapping the plugin runtime.","commonSituations":"Kernel-side defects during plugin bootstrap; seen when loading a plugin whose runtime setup fails before any plugin JS executes.","solutions":["Inspect the wrapped %v detail and report it upstream with the plugin name","Update the kernel to the latest version","Disable other plugins to rule out initialization interference","Retry loading the plugin to rule out a transient failure"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  await loadPlugin(p);\n} catch (e) {\n  if (String(e.message).startsWith('injectLogger:')) {\n    console.error('Logger API failed to install:', e.message);\n  }\n}","preventionTips":["Keep the kernel updated; bootstrap injection panics are kernel-internal","Feature-check siyuan.logger before use in plugin code","Include the full wrapped error text in bug reports"],"tags":["goja","plugin-init","panic","logger"],"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"}