{"record":{"id":"5f611d01f59e3dce","repo":"alibaba/open-code-review","slug":"invalid-color-value-q-must-be-one-of-auto-alw","errorCode":null,"errorMessage":"invalid --color value %q: must be one of auto, always, never","messagePattern":"invalid --color value %q: must be one of auto, always, never","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/color.go","lineNumber":48,"sourceCode":")\n\n// addColorFlags registers the color control. It is persistent on the root\n// command so every subcommand inherits identical behavior, and so\n// `ocr --color=never review` and `ocr review --color=never` are equivalent.\nfunc addColorFlags(cmd *cobra.Command) {\n\tcmd.PersistentFlags().StringVar(&colorMode, \"color\", colorModeAuto,\n\t\t\"when to emit ANSI color: auto (only when stdout is a terminal), always, or never\")\n\tcmd.RegisterFlagCompletionFunc(\"color\", completeEnum(colorModeAuto, colorModeAlways, colorModeNever))\n}\n\n// validateColorMode rejects unknown --color values instead of silently treating\n// them as auto, so a typo like --color=yes is reported rather than ignored.\nfunc validateColorMode(mode string) error {\n\tswitch mode {\n\tcase colorModeAuto, colorModeAlways, colorModeNever:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid --color value %q: must be one of auto, always, never\", mode)\n\t}\n}\n\n// resolveColor decides whether ANSI sequences may be written to stdout.\n//\n// Precedence, highest first:\n//  1. --color=never         → off\n//  2. --color=always        → on, even into a pipe (for `| less -R`)\n//  3. TERM=dumb              → off\n//  4. stdout is a terminal  → on, otherwise off\nfunc resolveColor() bool {\n\tif colorMode == colorModeNever {\n\t\treturn false\n\t}\n\tif colorMode == colorModeAlways {\n\t\treturn true\n\t}\n\tif strings.EqualFold(os.Getenv(\"TERM\"), \"dumb\") {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/color.go#L30-L66","documentation":"validateColorMode validates the --color flag, which controls ANSI color output. Only the exact values auto, always, and never are accepted; anything else (including intuitive aliases like yes, true, or on) is rejected so a typo is reported instead of silently treated as auto.","triggerScenarios":"Running any ocr command with `--color <value>` where value is not exactly `auto`, `always`, or `never` — e.g. `--color=yes`, `--color=true`, `--color=ALWAYS`, `--color=never ` (trailing space via script variable).","commonSituations":"Porting CI scripts from tools that accept --color=yes/--color=force; typos like --color=alwys; uppercase values in shell variables sourced from config; spaces from unquoted environment variables.","solutions":["Use one of the exact values: `--color=auto`, `--color=always`, or `--color=never`.","Map legacy values in scripts: replace `--color=yes` with `--color=always` and `--color=no` with `--color=never`.","If the value comes from an environment variable, quote and normalize it: `--color=\"${OCR_COLOR:-auto}\"` with OCR_COLOR validated beforehand.","Run `ocr --help` to confirm the accepted values."],"exampleFix":"// before\nocr review --color=yes\n// after\nocr review --color=always","handlingStrategy":"validation","validationCode":"// shell: normalize and validate the color value before invoking ocr\ncase \"$OCR_COLOR\" in\n  auto|always|never) ;;\n  yes|true|1) OCR_COLOR=always ;;\n  no|false|0) OCR_COLOR=never ;;\n  *) echo \"invalid --color: $OCR_COLOR (use auto|always|never)\"; exit 2 ;;\nesac","typeGuard":null,"tryCatchPattern":"out, err := cmd.CombinedOutput()\nif err != nil && strings.Contains(string(out), \"invalid --color value\") {\n\treturn fmt.Errorf(\"fix --color flag: %s\", out)\n}","preventionTips":["Always spell --color values lowercase: auto, always, never.","In scripts, define a whitelist map for legacy values (yes->always, no->never).","Quote flag values from variables to avoid stray spaces: --color=\"$MODE\"."],"tags":["cli","flag-validation","color-output"],"backgroundTag":"invalid-flag-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}