siyuan-note/siyuan · error

injectLogger: %v

Error message

injectLogger: %v

What it means

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.

Source

Thrown at kernel/plugin/api_logger.go:56

}

func (p *Printer) Error(s string) {
	go print(p.name, s, logging.LogErrorf)
}

// print logs the message line by line with the plugin name as prefix, using the provided log function.
func print(name, s string, logf func(format string, v ...any)) {
	rows := strings.SplitSeq(s, "\n")
	for row := range rows {
		logf("[plugin:%s] %s", name, row)
	}
}

// injectLogger adds siyuan.logger to the goja context.
func injectLogger(p *KernelPlugin, rt *goja.Runtime, siyuan *goja.Object) (err error) {
	defer func() {
		if r := recover(); r != nil {
			err = fmt.Errorf("injectLogger: %v", r)
		}
	}()

	logger := rt.NewObject()

	lo.Must0(logger.Set("trace", rt.ToValue(loggerWrapper(p, logging.LogTracef))))
	lo.Must0(logger.Set("debug", rt.ToValue(loggerWrapper(p, logging.LogDebugf))))
	lo.Must0(logger.Set("info", rt.ToValue(loggerWrapper(p, logging.LogInfof))))
	lo.Must0(logger.Set("warn", rt.ToValue(loggerWrapper(p, logging.LogWarnf))))
	lo.Must0(logger.Set("error", rt.ToValue(loggerWrapper(p, logging.LogErrorf))))

	lo.Must0(ObjectFreeze(rt, logger))

	lo.Must0(siyuan.Set("logger", logger))
	return
}

// loggerWrapper returns a JS-callable function that logs a message at the given level.

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Restart the kernel so the plugin runtime is rebuilt cleanly
  2. Update kernel and plugins to compatible versions
  3. Inspect kernel logs for the wrapped panic detail (%v) to find the failing logger registration
  4. Isolate by disabling plugins one by one to find one corrupting the worker
Defensive patterns

Strategy: try-catch

Try / catch

try { startPluginRuntime(); } catch (e) { if (String(e).startsWith("injectLogger:")) { restartKernelPluginHost(); } else { throw e; } }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/708553bdec98d8cd. Report an issue: GitHub.