{"record":{"id":"82b4c32a5149065b","repo":"urfave/cli","slug":"invalid-value-q-for-flag-s-v","errorCode":null,"errorMessage":"invalid value %q for flag -%s: %v","messagePattern":"invalid value %q for flag -(.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"command.go","lineNumber":360,"sourceCode":"\tnewArgs := &stringSliceArgs{v: rawArgs}\n\n\treturn newArgs\n}\n\n// Root returns the Command at the root of the graph\nfunc (cmd *Command) Root() *Command {\n\tif cmd.parent == nil {\n\t\treturn cmd\n\t}\n\n\treturn cmd.parent.Root()\n}\n\nfunc (cmd *Command) set(fName string, f Flag, val string) error {\n\tcmd.setFlags[f] = struct{}{}\n\tcmd.setMultiValueParsingConfig(f)\n\tif err := f.Set(fName, val); err != nil {\n\t\treturn fmt.Errorf(\"invalid value %q for flag -%s: %v\", val, fName, err)\n\t}\n\treturn nil\n}\n\nfunc (cmd *Command) lFlag(name string) Flag {\n\tfor _, f := range cmd.allFlags() {\n\t\tif slices.Contains(f.Names(), name) {\n\t\t\ttracef(\"flag found for name %[1]q (cmd=%[2]q)\", name, cmd.Name)\n\t\t\treturn f\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (cmd *Command) hasPersistentFlagOnAncestor(fl Flag) bool {\n\tfor pCmd := cmd.parent; pCmd != nil; pCmd = pCmd.parent {\n\t\tfor _, pFl := range pCmd.allFlags() {\n\t\t\tif pFl != fl {","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/urfave/cli/blob/1a4deb4f5a35ee12706602698dc0527d44c14b19/command.go#L342-L378","documentation":"Command.set invokes the flag's Set implementation and, on failure, wraps the error as fmt.Errorf(\"invalid value %q for flag -%s: %v\", val, fName, err). This is the common wrapper for any flag value parse failure during command flag parsing (parseFlags), so the underlying cause (strconv errors, timestamp layouts, etc.) is nested in %v.","triggerScenarios":"Any command line where a flag receives a value its type cannot parse: --port abc for an IntFlag, --deadline not-a-date for a TimestampFlag, --debug maybe for a BoolFlag. parseFlags calls set for each flag occurrence.","commonSituations":"Typos in flag values, environment-driven defaults with bad content, scripts interpolating empty variables into flag values, or version upgrades changing accepted formats.","solutions":["Fix the value so it parses for the flag's type; read the trailing %v cause for the specific parse failure.","Run the command with --help to confirm each flag's expected value type.","In code that builds command lines programmatically, validate/serialize values before passing them."],"exampleFix":"// before\nmyapp --port abc\n// after\nmyapp --port 8080","handlingStrategy":"try-catch","validationCode":"// validate a known int flag before running\nif v, ok := os.LookupEnv(\"MYAPP_PORT\"); ok {\n\tif _, err := strconv.Atoi(v); err != nil {\n\t\treturn fmt.Errorf(\"MYAPP_PORT must be an integer, got %q\", v)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(ctx, os.Args); err != nil {\n\tvar prefixed string\n\tif strings.HasPrefix(err.Error(), \"invalid value \\\"\") && strings.Contains(err.Error(), \"for flag -\") {\n\t\tfmt.Fprintf(os.Stderr, \"bad flag value: %v\\n\", err)\n\t\tos.Exit(2)\n\t}\n\t_ = prefixed\n\treturn err\n}","preventionTips":["Check each flag's documented type with --help before use.","Never interpolate unvalidated env vars into flag values.","Parse the nested cause (%v) to distinguish e.g. strconv vs timestamp failures.","Add smoke tests running the CLI with the exact flag values used in scripts/CI."],"tags":["go","cli","flag-parsing","type-conversion"],"backgroundTag":"invalid-flag-value","analyzedSha":"1a4deb4f5a35ee12706602698dc0527d44c14b19","analyzedAt":"2026-08-31T18:42:09.451Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}