siyuan-note/siyuan · error

injectClient

Error message

injectClient: %v

What it means

injectClient builds the siyuan.client object inside the plugin's goja runtime and attaches an HTTP fetch bridge to the kernel. The whole setup runs under a recover() guard; any panic during object creation or function binding is converted into this error. It indicates an unexpected runtime failure while wiring the client API, not a normal usage error.

Solutions

  1. Retry loading the plugin; the failure is often transient or runtime-related
  2. Check kernel logs for the full recovered panic value and stack
  3. Verify plugin runtime/memory settings and reduce plugin concurrency if OOM is suspected
  4. Report the panic value with plugin name and version if reproducible
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await loadPlugin(p);
} catch (e) {
  if (String(e).startsWith("injectClient:")) {
    logAndRetry(p); // transient runtime failure; report if persistent
  }
}

Prevention

When it happens

Trigger: A panic inside rt.NewObject(), client.Set(...), or the ToValue wrappers during plugin runtime initialization — e.g. a corrupted runtime, out-of-memory, or a bug in a native callback registered on the client object.

Common situations: Kernel-side bugs or resource exhaustion during plugin boot; a plugin runtime being torn down while injectClient is still running; rarely hit by plugin authors directly.

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@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/bc6785656b9db158. Report an issue: GitHub.

Appendix: source

Thrown at kernel/plugin/api_client.go:42

	"net/http"
	"strings"
	"sync"
	"sync/atomic"

	"github.com/dop251/goja"
	"github.com/lxzan/gws"
	sse "github.com/r3labs/sse/v2"
	"github.com/samber/lo"
	"github.com/siyuan-note/logging"
	"github.com/siyuan-note/siyuan/kernel/model"
	"github.com/siyuan-note/siyuan/kernel/util"
)

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

	client := rt.NewObject()

	lo.Must0(client.Set("fetch", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {
		promise, resolve, reject := rt.NewPromise()

		var argErr error
		var path string
		method := "GET"
		headers := map[string]string{}
		var bodyString *string
		var bodyBytes *[]byte

		if goja.IsString(call.Argument(0)) {
			path = call.Argument(0).String()
		} else {

View on GitHub (pinned to 9f775e8a12)