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

  1. Use exactly one '@': protocol on the left, address on the right ('unix@/tmp/geerpc.sock').
  2. Normalize URLs to the protocol@addr form before dialing (strip scheme://).
  3. 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

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


AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03). Data as JSON: /api/errors/805217f997e882d2. Report an issue: GitHub.