{"record":{"id":"e98a4f680abe294e","repo":"wavetermdev/waveterm","slug":"color-must-be-in-rrggbb-or-rrggbbaa-format","errorCode":null,"errorMessage":"color must be in #RRGGBB or #RRGGBBAA format","messagePattern":"color must be in #RRGGBB or #RRGGBBAA format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":72,"sourceCode":"\tsetBgCmd.Flags().Float64Var(&setBgOpacity, \"opacity\", 0.5, \"background opacity (0.0-1.0)\")\n\tsetBgCmd.Flags().BoolVar(&setBgTile, \"tile\", false, \"tile the background image\")\n\tsetBgCmd.Flags().BoolVar(&setBgCenter, \"center\", false, \"center the image without scaling\")\n\tsetBgCmd.Flags().StringVar(&setBgSize, \"size\", \"auto\", \"size for centered images (px, %, or auto)\")\n\tsetBgCmd.Flags().BoolVar(&setBgClear, \"clear\", false, \"clear the background\")\n\tsetBgCmd.Flags().BoolVar(&setBgPrint, \"print\", false, \"print the metadata without applying it\")\n\tsetBgCmd.Flags().StringVar(&setBgBorderColor, \"border-color\", \"\", \"block frame border color (#RRGGBB, #RRGGBBAA, or CSS color name)\")\n\tsetBgCmd.Flags().StringVar(&setBgActiveBorderColor, \"active-border-color\", \"\", \"block frame focused border color (#RRGGBB, #RRGGBBAA, or CSS color name)\")\n\n\tsetBgCmd.MarkFlagsMutuallyExclusive(\"tile\", \"center\")\n}\n\nfunc validateHexColor(color string) error {\n\tif !strings.HasPrefix(color, \"#\") {\n\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","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L54-L90","documentation":"After stripping the leading '#', validateHexColor requires exactly 6 hex digits (#RRGGBB) or 8 (#RRGGBBAA). Any other length — 3-digit shorthand like #F00, 4-digit #RGBA, or missing digits — fails this check before hex decoding is attempted.","triggerScenarios":"Calling `wsh setbg --border-color '#F00'` (3-digit), `'#RRGGBBAA'` with wrong digit count like '#1234567', or an empty '#'.","commonSituations":"Using CSS 3-digit shorthand that Wave's setbg doesn't support; pasting truncated hex strings; appending an alpha channel incorrectly.","solutions":["Expand 3-digit hex to 6 digits: '#F00' -> '#FF0000'.","For transparency use the 8-digit form '#RRGGBBAA' (or use the --opacity flag instead).","Count the digits: exactly 6 or exactly 8 hex characters after '#'."],"exampleFix":"// before\nwsh setbg --border-color '#F00'\n// after\nwsh setbg --border-color '#FF0000'","handlingStrategy":"validation","validationCode":"hexPart := strings.TrimPrefix(color, \"#\")\nif len(hexPart) != 6 && len(hexPart) != 8 {\n    return fmt.Errorf(\"color %q must be #RRGGBB or #RRGGBBAA\", color)\n}","typeGuard":"func isFullHexColor(c string) bool {\n    if !strings.HasPrefix(c, \"#\") { return false }\n    n := len(c) - 1\n    return n == 6 || n == 8\n}","tryCatchPattern":"if err := validateHexColor(c); err != nil {\n    if strings.Contains(err.Error(), \"#RRGGBB\") { c = expandShorthand(c) } // '#F00' -> '#FF0000'\n}","preventionTips":["Expand 3/4-digit CSS shorthand hex to 6/8 digits before use.","Use the --opacity flag for transparency instead of guessing 8-digit alpha.","Regex-check colors in scripts: ^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"],"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-08T10:18:20.063Z"}