{"record":{"id":"d3f781c3c6c98370","repo":"wavetermdev/waveterm","slug":"invalid-color-q-must-be-a-hex-color-rrggbb-or","errorCode":null,"errorMessage":"invalid color %q: must be a hex color (#RRGGBB or #RRGGBBAA) or a CSS color name","messagePattern":"invalid color %q: must be a hex color \\(#RRGGBB or #RRGGBBAA\\) or a CSS color name","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":86,"sourceCode":"\t\treturn fmt.Errorf(\"color must start with #\")\n\t}\n\tcolorHex := color[1:]\n\tif len(colorHex) != 6 && len(colorHex) != 8 {\n\t\treturn fmt.Errorf(\"color must be in #RRGGBB or #RRGGBBAA format\")\n\t}\n\t_, err := hex.DecodeString(colorHex)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid hex color: %v\", err)\n\t}\n\treturn nil\n}\n\nfunc validateColor(color string) error {\n\tif strings.HasPrefix(color, \"#\") {\n\t\treturn validateHexColor(color)\n\t}\n\tif !CssColorNames[strings.ToLower(color)] {\n\t\treturn fmt.Errorf(\"invalid color %q: must be a hex color (#RRGGBB or #RRGGBBAA) or a CSS color name\", color)\n\t}\n\treturn nil\n}\n\nfunc setBgRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tdefer func() {\n\t\tsendActivity(\"setbg\", rtnErr == nil)\n\t}()\n\n\tborderColorChanged := cmd.Flags().Changed(\"border-color\")\n\tactiveBorderColorChanged := cmd.Flags().Changed(\"active-border-color\")\n\n\tif borderColorChanged {\n\t\tif err := validateColor(setBgBorderColor); err != nil {\n\t\t\treturn fmt.Errorf(\"--border-color: %v\", err)\n\t\t}\n\t}\n\tif activeBorderColorChanged {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L68-L104","documentation":"validateColor accepts either a '#' hex color (delegated to validateHexColor) or a name present in the CssColorNames set. Anything else — invented names, misspelled CSS names, arbitrary strings — fails with this message telling you the two accepted forms.","triggerScenarios":"Calling `wsh setbg navyblue`, `wsh setbg \"dark gray\"` (not a valid CSS name, and contains a space), or any positional/flag color value that is neither '#' hex nor an exact CSS color name.","commonSituations":"Misspelling CSS names ('grey' vs 'gray' is fine, 'blueish' is not); using brand colors by name; forgetting quotes around multi-word names.","solutions":["Use an exact CSS color name (e.g. 'red', 'teal', 'darkgray') or a hex value '#RRGGBB'/'#RRGGBBAA'.","Check spelling against the CSS color name list; prefer hex to avoid name ambiguity.","Quote multi-word values and avoid spaces — use hex instead.","If you intended hex, don't forget the leading '#' so it routes to validateHexColor."],"exampleFix":"// before\nwsh setbg navyblue\n// after\nwsh setbg navy","handlingStrategy":"validation","validationCode":"if !strings.HasPrefix(color, \"#\") && !CssColorNames[strings.ToLower(color)] {\n    return fmt.Errorf(\"%q is neither a hex color nor a CSS color name\", color)\n}","typeGuard":"func isAcceptableColor(c string) bool {\n    if strings.HasPrefix(c, \"#\") { return regexp.MustCompile(`^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`).MatchString(c) }\n    return CssColorNames[strings.ToLower(c)]\n}","tryCatchPattern":"if err := validateColor(c); err != nil {\n    var suggest string\n    if d := nearestCssName(c); d != \"\" { suggest = d }\n    return fmt.Errorf(\"%v (did you mean %q?)\", err, suggest)\n}","preventionTips":["Pick colors from the standard CSS color name list or generate hex from a picker.","Prefer hex to avoid name spelling ambiguity.","Normalize case (names are matched lowercased) and trim whitespace first."],"tags":["cli","validation","color","argument"],"backgroundTag":"invalid-color-format","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}