urfave/cli · error

invalid value %q for argument %s: %v

Error message

invalid value %q for argument %s: %v

What it means

During single-value argument parsing, ArgumentsBase.Parse calls the argument's value.Set with the raw string; if that fails, the error is wrapped as fmt.Errorf("invalid value %q for argument %s: %v", ...). It reports which argument name failed, the offending raw value, and the underlying parse error, so it indicates bad input for that positional argument.

Source

Thrown at args.go:142

	return fmt.Sprintf(usageFormat, a.Name)
}

func (a *ArgumentBase[T, C, VC]) Parse(s []string) ([]string, error) {
	tracef("calling arg%[1] parse with args %[2]", a.Name, s)

	if a.Required && len(s) == 0 {
		return s, &errRequiredArguments{missingArguments: []string{a.Name}}
	}

	var vc VC
	var t T
	value := vc.Create(a.Value, &t, a.Config)
	a.value = &t

	tracef("attempting arg%[1] parse", &a.Name)
	if len(s) > 0 {
		if err := value.Set(s[0]); err != nil {
			return s, fmt.Errorf("invalid value %q for argument %s: %v", s[0], a.Name, err)
		}
		*a.value = value.Get().(T)
		tracef("set arg%[1] one value", a.Name, *a.value)
	}

	if a.Destination != nil {
		tracef("setting destination")
		*a.Destination = *a.value
	}

	if len(s) > 0 {
		return s[1:], nil
	}
	return s, nil
}

func (a *ArgumentBase[T, C, VC]) Get() any {
	if a.value != nil {

View on GitHub (pinned to 1a4deb4f5a)

Solutions

  1. Pass a value matching the argument's declared type (e.g. plain integer for an int argument).
  2. Read the wrapped %v cause in the message — it names the actual parse failure (e.g. strconv.Atoi syntax error).
  3. Loosen the argument to a string type and validate/convert yourself if flexible input is needed.

Example fix

// before
myapp count abc
// after
myapp count 42
Defensive patterns

Strategy: validation

Validate before calling

func isParsableInt(s string) bool {
	_, err := strconv.Atoi(s)
	return err == nil
}
// validate each positional arg before invoking the command

Try / catch

err := cmd.Run(ctx, os.Args)
var invErr error
if errors.As(err, &invErr) && strings.Contains(err.Error(), "invalid value") && strings.Contains(err.Error(), "for argument") {
	fmt.Fprintf(os.Stderr, "check positional argument values: %v\n", err)
	os.Exit(2)
}

Prevention

When it happens

Trigger: Parsing a command line where a positional argument of a typed (e.g. IntFlag-like/Float/Duration) argument receives a value that value.Set cannot convert, e.g. an int argument given "abc" or an out-of-range number like "99999999999999999999".

Common situations: Users passing non-numeric values to numeric args, copy-paste errors, or values with units ("10s" for an int, "1,000" with a comma).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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