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 the variadic options passed to Dial/DialTimeout (XDialer). The library supports at most one *Option argument; if the caller supplies two or more, it refuses to guess which to use and returns this error. Zero options or a single nil option falls back to DefaultOption.

Source

Thrown at gee-rpc/day4-timeout/client.go:200

// 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 *Client, err 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
	}
	// send options with server
	if err = json.NewEncoder(conn).Encode(opt); err != nil {

View on GitHub (pinned to cf36443821)

Solutions

  1. Pass at most one *Option to the dial function
  2. Merge desired settings into a single Option struct (set CodecType, ConnectionTimeout, etc. on one instance)
  3. Review wrapper functions that spread multiple option values into the variadic parameter

Example fix

// before
opt1 := &geerpc.Option{CodecType: "gob"}
opt2 := geerpc.DefaultOption
conn, err := geerpc.DialTimeout("tcp", addr, opt1, opt2)

// after
opt := &geerpc.Option{CodecType: "gob"}
conn, err := geerpc.DialTimeout("tcp", addr, opt)
Defensive patterns

Strategy: validation

Validate before calling

// validate options before dialing
func makeOpts(opts ...*geerpc.Option) ([]*geerpc.Option, error) {
	if len(opts) > 1 {
		return nil, fmt.Errorf("expected at most 1 option, got %d", len(opts))
	}
	return opts, nil
}

Try / catch

conn, err := geerpc.DialTimeout("tcp", addr, opt)
if err != nil {
	if strings.Contains(err.Error(), "number of options is more than 1") {
		// fix call site: pass a single merged option
	}
}

Prevention

When it happens

Trigger: DialTimeout("tcp", addr, opt1, opt2) or any dial function invoked with more than one *Option value in the variadic opts parameter.

Common situations: Migrating code that used to pass (timeout, option) and moving fields into Option incorrectly; calling a wrapper that forwards its own variadic slice plus an explicit option; copy-paste leaving a leftover default option argument.

Related errors


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