{"record":{"id":"5767da44254ad984","repo":"wavetermdev/waveterm","slug":"invalid-hex-color-v","errorCode":null,"errorMessage":"invalid hex color: %v","messagePattern":"invalid hex color: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":76,"sourceCode":"\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\nfunc setBgRun(cmd *cobra.Command, args []string) (rtnErr error) {\n\tdefer func() {\n\t\tsendActivity(\"setbg\", rtnErr == nil)\n\t}()","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L58-L94","documentation":"The value passed the '#' and length checks, but hex.DecodeString failed because the digits are not valid hexadecimal (e.g. '#GGHHII'). The underlying encoding/hex error is wrapped with \"invalid hex color: %v\".","triggerScenarios":"Calling `wsh setbg --border-color '#GGGGGG'` or any 6/8-character string after '#' containing non-hex characters (g-z, symbols, spaces).","commonSituations":"Typos like #0O0OOO (letter O vs zero); pasting a placeholder such as #RRGGBB literally; hidden whitespace or unicode characters pasted into the argument.","solutions":["Use only characters 0-9 and A-F (case-insensitive) in the hex portion.","Validate locally: `python3 -c \"int('GGGGGG',16)\"` or an online hex checker to confirm.","Re-type the value rather than pasting to eliminate hidden characters; or use a CSS color name instead."],"exampleFix":"// before\nwsh setbg '#GGGGGG'\n// after\nwsh setbg '#GGGGGG'  ->  wsh setbg '#999999'","handlingStrategy":"validation","validationCode":"hexPart := strings.TrimPrefix(color, \"#\")\nif _, err := hex.DecodeString(hexPart); err != nil {\n    return fmt.Errorf(\"color %q contains non-hex characters\", color)\n}","typeGuard":"var hexRe = regexp.MustCompile(`^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`)\nfunc isHexColor(c string) bool { return hexRe.MatchString(c) }","tryCatchPattern":"if err := validateHexColor(c); err != nil {\n    if strings.Contains(err.Error(), \"invalid hex color\") { /* re-prompt or fall back to a CSS name */ }\n}","preventionTips":["Only use characters 0-9 A-F after '#' (watch for O vs 0, B vs 8).","Never paste literal placeholders like #RRGGBB.","Regex-validate colors before passing to wsh in scripts."],"tags":["cli","validation","color","hex"],"backgroundTag":"invalid-color-format","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}