urfave/cli · error
could not parse %[1]q as %[2]T value from %[3]s for flag %[4
Error message
could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s
What it means
BoolWithInverseFlag.PostParse applies the flag's value from its configured Sources (env/config). If the sourced string cannot be parsed as the flag's boolean value, Set fails and PostParse wraps it as 'could not parse "<val>" as <type> value from <source> for flag <name>: <err>'.
Source
Thrown at flag_bool_with_inverse.go:104
if bif.Validator != nil && bif.ValidateDefaults {
if err := bif.Validator(bif.value.Get().(bool)); err != nil {
return err
}
}
bif.applied = true
return nil
}
func (bif *BoolWithInverseFlag) PostParse() error {
tracef("postparse (flag=%[1]q)", bif.Name)
if !bif.hasBeenSet {
if val, source, found := bif.Sources.LookupWithSource(); found {
if val == "" {
val = "false"
}
if err := bif.Set(bif.Name, val); err != nil {
return fmt.Errorf(
"could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s",
val, bif.Value, source, bif.Name, err,
)
}
bif.hasBeenSet = true
}
}
return nil
}
func (bif *BoolWithInverseFlag) Set(name, val string) error {
if bif.count > 0 && bif.OnlyOnce {
return fmt.Errorf("can't duplicate this flag")
}
bif.hasBeenSet = trueView on GitHub (pinned to 1a4deb4f5a)
Solutions
- Set the env/config value to a parser-accepted boolean (Go strconv.ParseBool forms: 1, t, T, true, TRUE, 0, f, F, false, FALSE)
- Remove or empty the offending source value (empty is treated as false)
- Normalize the value before it reaches the CLI, or switch the source to a validated one
Example fix
// before export MYFLAG=yes // after export MYFLAG=true
Defensive patterns
Strategy: validation
Validate before calling
// validate env value mapped to the flag before running
v := os.Getenv("MYFLAG")
if v != "" {
if _, err := strconv.ParseBool(v); err != nil {
return fmt.Errorf("MYFLAG=%q is not a valid bool", v)
}
} Type guard
func isParseableBool(s string) bool {
_, err := strconv.ParseBool(s)
return err == nil
} Try / catch
if err := cmd.Run(os.Args); err != nil {
if strings.Contains(err.Error(), "could not parse") {
fmt.Fprintln(os.Stderr, "check the env/config value for flag; use true/false")
os.Exit(2)
}
return err
} Prevention
- Only set mapped env vars to strconv.ParseBool-accepted values (1,t,true,0,f,false)
- Scrub human-style booleans ('yes','on') from shell profiles and CI configs
- Prefer CLI occurrence over sourced values, and test PostParse with your real env
When it happens
Trigger: An environment variable or config source mapped to the flag contains a non-boolean string (e.g. 'yes', 'on', 'maybe', or whitespace); empty values are coerced to "false" before parsing, but any other unparseable string errors.
Common situations: Env vars set to 'TRUE'/'yes' from shell conventions; config files with human-style booleans; typos like 'ture'; inheriting vars from parent processes with unexpected values.
Related errors
- could not parse %[1]q as %[2]T value from %[3]s for flag %[4
- item %q is missing separator %q
- no such flag -%s
- flag needs an argument: %s
- flag provided but not defined: -%s
AI-assisted analysis of urfave/cli@1a4deb4f5a (2026-08-31).
Data as JSON: /api/errors/b038438e2f6a783a.
Report an issue: GitHub.