{"record":{"id":"b038438e2f6a783a","repo":"urfave/cli","slug":"could-not-parse-1-q-as-2-t-value-from-3-s-fo","errorCode":null,"errorMessage":"could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s","messagePattern":"could not parse %\\[1\\]q as %\\[2\\]T value from %\\[3\\]s for flag %\\[4\\]s: %\\[5\\]s","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"flag_bool_with_inverse.go","lineNumber":104,"sourceCode":"\tif bif.Validator != nil && bif.ValidateDefaults {\n\t\tif err := bif.Validator(bif.value.Get().(bool)); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tbif.applied = true\n\treturn nil\n}\n\nfunc (bif *BoolWithInverseFlag) PostParse() error {\n\ttracef(\"postparse (flag=%[1]q)\", bif.Name)\n\n\tif !bif.hasBeenSet {\n\t\tif val, source, found := bif.Sources.LookupWithSource(); found {\n\t\t\tif val == \"\" {\n\t\t\t\tval = \"false\"\n\t\t\t}\n\t\t\tif err := bif.Set(bif.Name, val); err != nil {\n\t\t\t\treturn fmt.Errorf(\n\t\t\t\t\t\"could not parse %[1]q as %[2]T value from %[3]s for flag %[4]s: %[5]s\",\n\t\t\t\t\tval, bif.Value, source, bif.Name, err,\n\t\t\t\t)\n\t\t\t}\n\n\t\t\tbif.hasBeenSet = true\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (bif *BoolWithInverseFlag) Set(name, val string) error {\n\tif bif.count > 0 && bif.OnlyOnce {\n\t\treturn fmt.Errorf(\"can't duplicate this flag\")\n\t}\n\n\tbif.hasBeenSet = true","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/flag_bool_with_inverse.go#L86-L122","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nexport MYFLAG=yes\n// after\nexport MYFLAG=true","handlingStrategy":"validation","validationCode":"// validate env value mapped to the flag before running\nv := os.Getenv(\"MYFLAG\")\nif v != \"\" {\n    if _, err := strconv.ParseBool(v); err != nil {\n        return fmt.Errorf(\"MYFLAG=%q is not a valid bool\", v)\n    }\n}","typeGuard":"func isParseableBool(s string) bool {\n    _, err := strconv.ParseBool(s)\n    return err == nil\n}","tryCatchPattern":"if err := cmd.Run(os.Args); err != nil {\n    if strings.Contains(err.Error(), \"could not parse\") {\n        fmt.Fprintln(os.Stderr, \"check the env/config value for flag; use true/false\")\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["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"],"tags":["go","cli","flags","env-var","parsing"],"backgroundTag":"invalid-boolean-env-var","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}