urfave/cli · error

parse error

Error message

parse error

What it means

This error is returned by (*boolValue).Set when the string supplied for a boolean flag cannot be parsed by strconv.ParseBool. Go only accepts "1", "t", "T", "TRUE", "true", "True", "0", "f", "F", "FALSE", "false", "False" for booleans, so any other value is rejected and replaced with this opaque "parse error" message. The original strconv error text is discarded, which makes the cause less obvious to users.

Source

Thrown at flag_bool.go:62

	}
	return &boolValue{
		destination: p,
		count:       c.Count,
	}
}

// ToString formats the bool value
func (b boolValue) ToString(value bool) string {
	b.destination = &value
	return b.String()
}

// Below functions are to satisfy the flag.Value interface

func (b *boolValue) Set(s string) error {
	v, err := strconv.ParseBool(s)
	if err != nil {
		err = errors.New("parse error")
		return err
	}
	*b.destination = v
	if b.count != nil {
		*b.count = *b.count + 1
	}
	return err
}

func (b *boolValue) Get() any { return *b.destination }

func (b *boolValue) String() string {
	return strconv.FormatBool(*b.destination)
}

func (b *boolValue) IsBoolFlag() bool { return true }

View on GitHub (pinned to 1a4deb4f5a)

Solutions

  1. Use one of the accepted values: true/false, t/f, 1/0, or capitalized variants (TRUE, True, False).
  2. If you need yes/no or on/off semantics, use a string flag and convert it yourself, or a custom flag.Value implementation.
  3. Check the shell script/CI variable feeding the flag for unexpected values like "yes", "on", or whitespace.

Example fix

// before
myapp -verbose=yes
// after
myapp -verbose=true
Defensive patterns

Strategy: validation

Validate before calling

func isValidBoolString(s string) bool {
	_, err := strconv.ParseBool(s)
	return err == nil
}
// call: isValidBoolString(flagValue) before setting/parsing

Try / catch

if err := flag.Set("verbose", v); err != nil {
	if err.Error() == "parse error" {
		fmt.Fprintf(os.Stderr, "-verbose expects true/false, got %q\n", v)
		os.Exit(2)
	}
	return err
}

Prevention

When it happens

Trigger: Calling Set with a value outside strconv.ParseBool's accepted set, e.g. flag parsing receives -verbose=yes, -verbose=on, or an empty string. It surfaces whenever a BoolFlag's Set method is invoked through command-line parsing or programmatically via flag.Set.

Common situations: Users writing shell conventions (-flag=yes/no), scripts setting flags from environment variables with values like "YES" or "on", or CI configs passing truthy strings the stdlib does not recognize.

Understand the failure class

Related errors


AI-assisted analysis of urfave/cli@1a4deb4f5a (2026-08-31). Data as JSON: /api/errors/48abb0d4f9c56d62. Report an issue: GitHub.