{"record":{"id":"bf25c597ab1bb912","repo":"siyuan-note/siyuan","slug":"invalid-jsonrpc-version-s-plugin-rpc","errorCode":null,"errorMessage":"invalid jsonrpc version: %s","messagePattern":"invalid jsonrpc version: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/apicontract/plugin_rpc.go","lineNumber":182,"sourceCode":"\treturn json.Unmarshal(data, &o.Value)\n}\n\nfunc parsePluginRPCCall(data []byte) PluginRPCParsedCall {\n\ttype JsonRpcRequestObject struct {\n\t\tJsonRpc rpcOptional[string]    `json:\"jsonrpc\"`\n\t\tMethod  rpcOptional[string]    `json:\"method\"`\n\t\tParams  rpcOptional[JSONValue] `json:\"params\"`\n\t\tID      rpcOptional[JSONValue] `json:\"id\"`\n\t}\n\tvar fields JsonRpcRequestObject\n\terr := json.Unmarshal(data, &fields)\n\tvar id PluginRPCID\n\tif err == nil {\n\t\tswitch {\n\t\tcase !fields.JsonRpc.Exists:\n\t\t\terr = fmt.Errorf(\"missing jsonrpc field\")\n\t\tcase fields.JsonRpc.Value != \"2.0\":\n\t\t\terr = fmt.Errorf(\"invalid jsonrpc version: %s\", fields.JsonRpc.Value)\n\t\tcase !fields.Method.Exists || fields.Method.IsNull:\n\t\t\terr = fmt.Errorf(\"missing method field\")\n\t\tdefault:\n\t\t\tif fields.ID.Exists && !fields.ID.IsNull {\n\t\t\t\traw, _ := json.Marshal(fields.ID.Value)\n\t\t\t\terr = json.Unmarshal(raw, &id)\n\t\t\t}\n\t\t}\n\t}\n\tif err != nil {\n\t\tmessage := strings.ReplaceAll(err.Error(), \"apicontract.JsonRpcRequestObject\", \"plugin.JsonRpcRequestObject\")\n\t\tfailure := RPCErrorResponse(-32600, \"Invalid Request\", \"RPC request is not a valid JSON-RPC object: \"+message)\n\t\treturn PluginRPCParsedCall{Error: &failure}\n\t}\n\treturn PluginRPCParsedCall{Request: &PluginRPCCall{Method: fields.Method.Value, Params: fields.Params.Value, ParamsPresent: fields.Params.Exists, ParamsNull: fields.Params.IsNull, ID: id, IDPresent: fields.ID.Exists}}\n}\n\n// RPC 请求保留批量中的单项结构错误，参数形状错误仍交给调用分发处理通知语义。","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/apicontract/plugin_rpc.go#L164-L200","documentation":"The \"jsonrpc\" member is present but its value is not exactly the string \"2.0\". JSON-RPC 2.0 requires this exact version string; anything else (\"1.0\", \"2.00\", 2.0 as a number, etc.) is rejected as an Invalid Request and converted to a -32600 error reply.","triggerScenarios":"DecodePluginRPC parses a request whose jsonrpc field is \"1.0\", \"1.1\", \"2.0 \" (whitespace), or a JSON number 2.0 instead of the string \"2.0\".","commonSituations":"Clients written for the legacy JSON-RPC 1.0 protocol, serializers that emit 2.0 unquoted, version string built with format specifiers adding whitespace, or copy-pasted spec examples from 1.x docs.","solutions":["Set the field to exactly the string \"2.0\" (case-sensitive, no whitespace)","Ensure the client serializes it as a JSON string, not a number","Check for trailing whitespace or encoding issues in the payload generator"],"exampleFix":"// before\n{\"jsonrpc\":\"1.0\",\"method\":\"plugin/invoke\",\"id\":1}\n// after\n{\"jsonrpc\":\"2.0\",\"method\":\"plugin/invoke\",\"id\":1}","handlingStrategy":"validation","validationCode":"var probe struct{ JsonRpc *string `json:\"jsonrpc\"` }\nif json.Unmarshal(payload, &probe) != nil || probe.JsonRpc == nil || *probe.JsonRpc != \"2.0\" { return errors.New(\"jsonrpc must be the string \\\"2.0\\\"\") }","typeGuard":null,"tryCatchPattern":"if call.Error != nil && call.Error.Error != nil && call.Error.Error.Code == -32600 {\n    log.Printf(\"request rejected: %s\", call.Error.Error.Message)\n}","preventionTips":["Define a shared constant for the version string and interpolate it, never type \"2.0\" inline per call","Serialize the version as a quoted JSON string, not a number","Migrate clients off JSON-RPC 1.x before switching endpoints"],"tags":["json-rpc","protocol-version","validation"],"backgroundTag":"invalid-enum-value","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"}