geektutu/7days-golang · error

number of options is more than 1

Error message

number of options is more than 1

What it means

Guard in parseOptions: it accepts zero options (default) or exactly one custom option, so passing two or more *Option values is a programming error. It fires at Dial time when the caller supplies more than one option argument.

Source

Thrown at gee-rpc/day2-client/client.go:192

	}
	client.send(call)
	return call
}

// Call invokes the named function, waits for it to complete,
// and returns its error status.
func (client *Client) Call(serviceMethod string, args, reply interface{}) error {
	call := <-client.Go(serviceMethod, args, reply, make(chan *Call, 1)).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

  1. Pass at most one *Option to Dial; modify the single option's fields instead of passing several.
  2. Use geerpc.DefaultOption when no customization is needed and omit options entirely.
  3. Build one Option value that merges all desired settings before calling Dial.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at gee-rpc/day2-client/client.go:192 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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