{"record":{"id":"ce8ed29c464b3603","repo":"siyuan-note/siyuan","slug":"missing-method-field","errorCode":null,"errorMessage":"missing method field","messagePattern":"missing method field","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/rpc.go","lineNumber":121,"sourceCode":"\t\tParams  util.Optional[any]    `json:\"params\"`\n\t\tID      util.Optional[any]    `json:\"id\"`\n\t}\n\trequest := JsonRpcRequestObject{}\n\tif err := decoder.Decode(&request); err != nil {\n\t\treturn err\n\t}\n\n\t// Validate jsonrpc field\n\tif !request.JsonRpc.Exists {\n\t\treturn fmt.Errorf(\"missing jsonrpc field\")\n\t}\n\tif request.JsonRpc.Value != JsonRpcVersion {\n\t\treturn fmt.Errorf(\"invalid jsonrpc version: %s\", request.JsonRpc.Value)\n\t}\n\n\t// Validate method field\n\tif !request.Method.HasValue() {\n\t\treturn fmt.Errorf(\"missing method field\")\n\t}\n\n\t// Validate id field\n\tif !request.ID.Exists {\n\t} else if request.ID.IsNull {\n\t} else if _, ok := request.ID.Value.(string); ok {\n\t} else if _, ok := request.ID.Value.(float64); ok {\n\t} else {\n\t\treturn fmt.Errorf(\"invalid id field: must be string, number, null or omitted\")\n\t}\n\n\tr.JsonRpc = request.JsonRpc.Value\n\tr.Method = request.Method.Value\n\tr.Params = request.Params\n\tr.ID = request.ID\n\treturn nil\n}\n","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/rpc.go#L103-L139","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Include a non-null method string in every request: {\"jsonrpc\":\"2.0\",\"method\":\"<name>\",\"id\":1}","Log the outgoing payload to confirm method is present and non-empty before send","Fix client code that builds the request from a possibly-undefined method variable","Verify the client library serializes required fields rather than omitting empty ones"],"exampleFix":"// before\n{\"jsonrpc\": \"2.0\", \"id\": 1}\n// after\n{\"jsonrpc\": \"2.0\", \"method\": \"ping\", \"id\": 1}","handlingStrategy":"validation","validationCode":"if (!body || typeof body.method !== \"string\" || body.method.length === 0) throw new Error(\"method is required and must be a non-empty string\");","typeGuard":"const hasMethod = (body) => body && typeof body.method === \"string\" && body.method.length > 0;","tryCatchPattern":"try { return await rpcSend(payload); } catch (e) { if (String(e).includes(\"missing method field\")) { console.error(\"payload sent:\", JSON.stringify(payload)); } throw e; }","preventionTips":["Always set method to a non-empty string in every request","Guard the method variable at call sites to avoid undefined being dropped by serializers","Use a shared request builder that requires method as a parameter","Log the outgoing body when RPC calls fail"],"tags":["json-rpc","validation","missing-field"],"backgroundTag":"empty-required-field","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"}