{"record":{"id":"000780029185cbb5","repo":"geektutu/7days-golang","slug":"h-error","errorCode":null,"errorMessage":"h.Error","messagePattern":"h\\.Error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day5-http-debug/client.go","lineNumber":151,"sourceCode":"\t\t}\n\t}\n}\n\nfunc (client *Client) receive() {\n\tvar err error\n\tfor err == nil {\n\t\tvar h codec.Header\n\t\tif err = client.cc.ReadHeader(&h); err != nil {\n\t\t\tbreak\n\t\t}\n\t\tcall := client.removeCall(h.Seq)\n\t\tswitch {\n\t\tcase call == nil:\n\t\t\t// it usually means that Write partially failed\n\t\t\t// and call was already removed.\n\t\t\terr = client.cc.ReadBody(nil)\n\t\tcase h.Error != \"\":\n\t\t\tcall.Error = fmt.Errorf(h.Error)\n\t\t\terr = client.cc.ReadBody(nil)\n\t\t\tcall.done()\n\t\tdefault:\n\t\t\terr = client.cc.ReadBody(call.Reply)\n\t\t\tif err != nil {\n\t\t\t\tcall.Error = errors.New(\"reading body \" + err.Error())\n\t\t\t}\n\t\t\tcall.done()\n\t\t}\n\t}\n\t// error occurs, so terminateCalls pending calls\n\tclient.terminateCalls(err)\n}\n\n// Go invokes the function asynchronously.\n// It returns the Call structure representing the invocation.\nfunc (client *Client) Go(serviceMethod string, args, reply interface{}, done chan *Call) *Call {\n\tif done == nil {","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day5-http-debug/client.go#L133-L169","documentation":"In gee-rpc/day5-http-debug's receive loop, when the server reports a failure via the response header's Error field, the client sets call.Error = fmt.Errorf(h.Error) — the surfaced message is the server-side error string itself. Typical server messages are \"rpc server: service X method Y not found\" and \"rpc server: failed to handle request: <panic or decode error>\".","triggerScenarios":"Calling a ServiceMethod that is not registered on the server (wrong service or method name); arguments cannot be decoded on the server; the service method panics and the server recovers, writing the recovered error into h.Error.","commonSituations":"Typos or refactors in \"Service.Method\" names; client/server have different registrations (e.g. only DotoriService registered with prefix); exported-method requirement violated on the server; arg/reply type mismatch causing server decode failure; panic inside the handler.","solutions":["Check the server's registration calls (geerpc.Register / RegisterName) and use the exact service and method names","Ensure the method is exported (capitalized) with two exported pointer parameters and one error return","Match the client args type to the server method's first parameter","Inspect server logs for the original panic message if the error text shows a recovered panic"],"exampleFix":"// before\nvar reply string\nerr := client.Call(\"Foo/sum\", req, &reply) // wrong separator/case\n// after\nerr := client.Call(\"Foo.Sum\", req, &reply) // matches srv.Register(new(Foo)) with exported Sum method","handlingStrategy":"try-catch","validationCode":"// before calling, ensure the server registered this method (client-side check is not possible;\n// guard the method name string)\nconst method = \"Foo.Sum\" // must match server registration exactly, case-sensitive\nif !strings.Contains(method, \".\") { return errors.New(\"ServiceMethod must be \\\"Service.Method\\\"\") }","typeGuard":null,"tryCatchPattern":"err := client.Call(\"Foo.Sum\", req, reply)\nif err != nil {\n\tif strings.Contains(err.Error(), \"not found\") {\n\t\t// wrong service/method name: fix registration or name\n\t} else if strings.Contains(err.Error(), \"failed to handle request\") {\n\t\t// server panic or decode error: check server logs, verify arg types\n\t}\n}","preventionTips":["Keep service/method name constants shared between server and client","Follow net/rpc rules: exported method, two exported pointer args, error return","Match client arg types to server method signatures exactly","Recover-and-log panics in server methods and inspect logs when h.Error surfaces them"],"tags":["rpc","server-side-error","method-not-found","panic"],"backgroundTag":"rpc-server-method-not-found","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}