siyuan-note/siyuan · error

missing method field

Error message

missing method field

What it means

Per JSON-RPC 2.0, every request must contain a string 'method' naming the procedure to invoke. JsonRpcRequest.UnmarshalJSON fails with 'missing method field' when the method member is absent or has no value. Without it the kernel cannot route the request to a handler.

Solutions

  1. Include a non-null method string in every request: {"jsonrpc":"2.0","method":"<name>","id":1}
  2. Log the outgoing payload to confirm method is present and non-empty before send
  3. Fix client code that builds the request from a possibly-undefined method variable
  4. Verify the client library serializes required fields rather than omitting empty ones

Example fix

// before
{"jsonrpc": "2.0", "id": 1}
// after
{"jsonrpc": "2.0", "method": "ping", "id": 1}
Defensive patterns

Strategy: validation

Validate before calling

if (!body || typeof body.method !== "string" || body.method.length === 0) throw new Error("method is required and must be a non-empty string");

Type guard

const hasMethod = (body) => body && typeof body.method === "string" && body.method.length > 0;

Try / catch

try { return await rpcSend(payload); } catch (e) { if (String(e).includes("missing method field")) { console.error("payload sent:", JSON.stringify(payload)); } throw e; }

Prevention

When it happens

Trigger: Posting a body like {"jsonrpc":"2.0","id":1} with no method key; method explicitly set to null; a serializer dropping empty-string/undefined fields before sending.

Common situations: Hand-written test payloads; generic RPC clients that send envelopes without a method; bugs where the method name variable is empty/undefined at call time.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/ce8ed29c464b3603. Report an issue: GitHub.

Appendix: source

Thrown at kernel/plugin/rpc.go:121

		Params  util.Optional[any]    `json:"params"`
		ID      util.Optional[any]    `json:"id"`
	}
	request := JsonRpcRequestObject{}
	if err := decoder.Decode(&request); err != nil {
		return err
	}

	// Validate jsonrpc field
	if !request.JsonRpc.Exists {
		return fmt.Errorf("missing jsonrpc field")
	}
	if request.JsonRpc.Value != JsonRpcVersion {
		return fmt.Errorf("invalid jsonrpc version: %s", request.JsonRpc.Value)
	}

	// Validate method field
	if !request.Method.HasValue() {
		return fmt.Errorf("missing method field")
	}

	// Validate id field
	if !request.ID.Exists {
	} else if request.ID.IsNull {
	} else if _, ok := request.ID.Value.(string); ok {
	} else if _, ok := request.ID.Value.(float64); ok {
	} else {
		return fmt.Errorf("invalid id field: must be string, number, null or omitted")
	}

	r.JsonRpc = request.JsonRpc.Value
	r.Method = request.Method.Value
	r.Params = request.Params
	r.ID = request.ID
	return nil
}

View on GitHub (pinned to 9f775e8a12)