geektutu/7days-golang · error
number of options is more than 1
Error message
number of options is more than 1
What it means
parseOptions validates that at most one *Option is supplied to NewClient/XDial. Passing more than one option argument is rejected because a single Option struct fully configures the client; the library cannot merge multiple option sets.
Source
Thrown at gee-rpc/day7-registry/client.go:203
// and returns its error status.
func (client *Client) Call(ctx context.Context, serviceMethod string, args, reply interface{}) error {
call := client.Go(serviceMethod, args, reply, make(chan *Call, 1))
select {
case <-ctx.Done():
client.removeCall(call.Seq)
return errors.New("rpc client: call failed: " + ctx.Err().Error())
case call := <-call.Done:
return call.Error
}
}
func parseOptions(opts ...*Option) (*Option, error) {
// if opts is nil or pass nil as parameter
if len(opts) == 0 || opts[0] == nil {
return DefaultOption, nil
}
if len(opts) != 1 {
return nil, errors.New("number of options is more than 1")
}
opt := opts[0]
opt.MagicNumber = DefaultOption.MagicNumber
if opt.CodecType == "" {
opt.CodecType = DefaultOption.CodecType
}
return opt, nil
}
func NewClient(conn net.Conn, opt *Option) (*Client, error) {
f := codec.NewCodecFuncMap[opt.CodecType]
if f == nil {
err := fmt.Errorf("invalid codec type %s", opt.CodecType)
log.Println("rpc client: codec error:", err)
return nil, err
}
// send options with server
if err := json.NewEncoder(conn).Encode(opt); err != nil {View on GitHub (pinned to cf36443821)
Solutions
- Merge settings into a single &Option{CodecType: ..., ConnectionTimeout: ...} struct and pass only it.
- Pass no option to use DefaultOption, or a single custom one.
- If wrapping, combine defaults with user overrides in one Option value before dialing.
Example fix
// before
client, err := geeRPC.XDial(addr, opt, anotherOpt) // errors
// after
merged := &geeRPC.Option{CodecType: opt.CodecType, ConnectionTimeout: anotherOpt.ConnectionTimeout}
client, err := geeRPC.XDial(addr, merged) Defensive patterns
Strategy: validation
Validate before calling
func buildOption(opts ...*geeRPC.Option) (*geeRPC.Option, error) {
if len(opts) > 1 { return nil, errors.New("at most one Option allowed") }
return opts[0], nil // or nil for DefaultOption
} Try / catch
if err != nil && err.Error() == "number of options is more than 1" { return fmt.Errorf("merge options into a single geeRPC.Option: %w", err) } Prevention
- Merge all settings into one Option struct before dialing.
- Do not pass functional-style option values as separate variadic args.
- Prefer passing nil (DefaultOption) and mutate a copy only when needed.
When it happens
Trigger: Calling geeRPC.NewClient(conn, opt1, opt2) or geeRPC.XDial(addr, opt1, opt2) with two or more variadic option arguments.
Common situations: Migrating from functional-options style APIs (WithCodec(...), WithTimeout(...)) and passing each as a separate argument, copy-pasted dial code appending an extra option, or wrapper functions forwarding both a default and a user option.
Related errors
- number of options is more than 1
- rpc discovery: not supported select mode
- connection is shut down
- reading body
- rpc client: call failed:
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/57ac6f2e26eadfb0.
Report an issue: GitHub.