siyuan-note/siyuan · error

method required

Error message

method required

What it means

Thrown by siyuan.rpc.broadcast() when called with no arguments. broadcast dispatches an RPC method invocation to all loaded plugins (inter-plugin messaging) and needs a method name string to route the call. With zero arguments there is no method to invoke, so the promise rejects before any dispatch.

Source

Thrown at kernel/plugin/api_rpc.go:147

		})
		if runErr != nil {
			logging.LogErrorf("[plugin:%s] siyuan.rpc.unbind worker run: %v", p.Name, runErr)
			if rejectErr := reject(rt.NewGoError(runErr)); rejectErr != nil {
				logging.LogErrorf("[plugin:%s] siyuan.rpc.unbind reject: %v", p.Name, rejectErr)
			}
		}

		return rt.ToValue(promise)
	})))

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

		var argErr error
		var method string
		var params util.Optional[any]
		if len(call.Arguments) < 1 {
			argErr = fmt.Errorf("method required")
		} else {
			if m := call.Argument(0); goja.IsString(m) {
				method = m.String()
			} else {
				argErr = fmt.Errorf("first argument must be method name string")
			}
			if argErr == nil {
				arg := call.Argument(1)
				if goja.IsUndefined(arg) {
					params.Value = nil
					params.Exists = false
					params.IsNull = false
				} else if goja.IsNull(arg) {
					params.Value = nil
					params.Exists = true
					params.IsNull = true
				} else {
					params.Value = arg.Export()

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Pass the target method name string as the first argument, e.g. broadcast('pluginB.onEvent').
  2. If the params are optional, still always include the method name as argument 0.
  3. Validate the method identifier is non-empty before broadcasting.

Example fix

// before
await siyuan.rpc.broadcast();
// after
await siyuan.rpc.broadcast('myPlugin.onData', { payload: 1 });
Defensive patterns

Strategy: validation

Validate before calling

if (arguments.length === 0 || typeof arguments[0] !== 'string') {
  throw new TypeError('broadcast requires a method name string');
}

Type guard

const isBroadcastTarget = (v) => typeof v === 'string' && v.length > 0;

Try / catch

try { await siyuan.rpc.broadcast(method, params); }
catch (e) { if (/method required/.test(String(e))) { /* method omitted: skip */ } else throw e; }

Prevention

When it happens

Trigger: await siyuan.rpc.broadcast() with an empty call, or broadcast called via .apply(ctx, []) where the arguments array was unexpectedly empty.

Common situations: Plugin builds its broadcast call from a config object whose 'method' field is optional and was omitted; or the developer confused broadcast (fan-out) with a no-arg ping and called it bare.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/bc49adabcbc0b898. Report an issue: GitHub.