geektutu/7days-golang · error
rpc client err: wrong format '%s', expect protocol@addr
Error message
rpc client err: wrong format '%s', expect protocol@addr
What it means
Day7-registry XDial rejects any rpcAddr that does not split into exactly two '@'-separated parts, returning this format error. Same contract as earlier days: protocol@addr, e.g. http@10.0.0.1:7001, tcp@10.0.0.1:9999, unix@/tmp/geerpc.sock.
Source
Thrown at gee-rpc/day7-registry/client.go:313
err = errors.New("unexpected HTTP response: " + resp.Status)
}
return nil, err
}
// DialHTTP connects to an HTTP RPC server at the specified network address
// listening on the default HTTP RPC path.
func DialHTTP(network, address string, opts ...*Option) (*Client, error) {
return dialTimeout(NewHTTPClient, network, address, opts...)
}
// XDial calls different functions to connect to a RPC server
// according the first parameter rpcAddr.
// rpcAddr is a general format (protocol@addr) to represent a rpc server
// eg, http@10.0.0.1:7001, tcp@10.0.0.1:9999, unix@/tmp/geerpc.sock
func XDial(rpcAddr string, opts ...*Option) (*Client, error) {
parts := strings.Split(rpcAddr, "@")
if len(parts) != 2 {
return nil, fmt.Errorf("rpc client err: wrong format '%s', expect protocol@addr", rpcAddr)
}
protocol, addr := parts[0], parts[1]
switch protocol {
case "http":
return DialHTTP("tcp", addr, opts...)
default:
// tcp, unix or other transport protocol
return Dial(protocol, addr, opts...)
}
}
View on GitHub (pinned to cf36443821)
Solutions
- Use exactly one '@': protocol on the left, address on the right ('unix@/tmp/geerpc.sock').
- Normalize URLs to the protocol@addr form before dialing (strip scheme://).
- Use Dial when the protocol is already known and fixed.
Example fix
// before
XDial("http://127.0.0.1:7001")
// after
XDial("http@127.0.0.1:7001") Defensive patterns
Strategy: validation
Validate before calling
func toRPCAddr(s string) string {
if strings.Contains(s, "://") {
u, _ := url.Parse(s)
return u.Scheme + "@" + u.Host
}
return s
}
// then verify: strings.Count(addr, "@") == 1 Try / catch
c, err := geerpc.XDial(toRPCAddr(rawAddr))
if err != nil {
if strings.Contains(err.Error(), "wrong format") {
return nil, fmt.Errorf("expected protocol@addr, got %q", rawAddr)
}
return nil, err
} Prevention
- Reject URLs and user@host strings at input boundaries; convert to protocol@addr.
- Never embed credentials in rpcAddr strings.
- Use unix@/path for local sockets rather than trying to encode paths with '@'.
- Document the expected format wherever addresses are configured.
When it happens
Trigger: XDial with a missing protocol prefix, an embedded 'user@host' style string, or an address containing multiple '@' characters.
Common situations: Passing an HTTP URL like 'http://host:9999' instead of 'http@host:9999'; credentials accidentally included in the address; registry templates producing malformed addresses.
Related errors
- rpc client err: wrong format '%s', expect protocol@addr
- rpc client err: wrong format '%s', expect protocol@addr
- rpc server: service/method request ill-formed:
- connection is shut down
- reading body
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/805217f997e882d2.
Report an issue: GitHub.