geektutu/7days-golang · error
h.Error
Error message
h.Error
What it means
Same mechanism as error 81 in day7-registry: when receive() reads a response whose header Error field is non-empty, the server reported a failure and the client converts h.Error into call.Error. The registry day adds heart-beat and registry features but the error path is unchanged.
Source
Thrown at gee-rpc/day7-registry/client.go:151
}
}
}
func (client *Client) receive() {
var err error
for err == nil {
var h codec.Header
if err = client.cc.ReadHeader(&h); err != nil {
break
}
call := client.removeCall(h.Seq)
switch {
case call == nil:
// it usually means that Write partially failed
// and call was already removed.
err = client.cc.ReadBody(nil)
case h.Error != "":
call.Error = fmt.Errorf(h.Error)
err = client.cc.ReadBody(nil)
call.done()
default:
err = client.cc.ReadBody(call.Reply)
if err != nil {
call.Error = errors.New("reading body " + err.Error())
}
call.done()
}
}
// error occurs, so terminateCalls pending calls
client.terminateCalls(err)
}
// Go invokes the function asynchronously.
// It returns the Call structure representing the invocation.
func (client *Client) Go(serviceMethod string, args, reply interface{}, done chan *Call) *Call {
if done == nil {View on GitHub (pinned to cf36443821)
Solutions
- Read the actual message in call.Error from Call() and fix the server-side cause.
- Confirm the service method name string matches the registered service exactly.
- Verify args and reply types are gob-compatible and identical on both sides.
Example fix
// before
client.Call("WrongSvc.Div", args, reply)
// after
client.Call("Arith.Div", args, reply) Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure server registered the service before dialing: // var _ = gee.Register(new(Arith))
Try / catch
err := client.Call("Arith.Div", args, reply)
var rpcErr error
if err != nil {
log.Printf("call %s failed: %v", "Arith.Div", err) // contains server h.Error
rpcErr = err
} Prevention
- Share method-name constants between client and server packages.
- Surface the full server error text to logs for diagnosis.
- Keep request/reply structs in a shared package to avoid gob mismatches.
- Handle expected domain errors (e.g. division by zero) explicitly in the client.
When it happens
Trigger: Server handler for the requested service/method returned an error; method not found; server failed to decode args or encode reply; call observed in the receive goroutine.
Common situations: Method name mismatch between client Call and server registration; wrong arg/reply types causing gob decode errors server-side; server panics converted to error responses.
Related errors
- h.Error
- connection is shut down
- reading body
- rpc client: call failed:
- number of options is more than 1
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/e77ff748a0a2a42c.
Report an issue: GitHub.