{"record":{"id":"fbd670eb34bed75c","repo":"wavetermdev/waveterm","slug":"color-must-start-with","errorCode":null,"errorMessage":"color must start with #","messagePattern":"color must start with #","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/wsh/cmd/wshcmd-setbg.go","lineNumber":68,"sourceCode":")\n\nfunc init() {\n\trootCmd.AddCommand(setBgCmd)\n\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)","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/cmd/wsh/cmd/wshcmd-setbg.go#L50-L86","documentation":"validateHexColor rejects any color argument that doesn't begin with '#' before attempting hex decoding. `wsh setbg --border-color` (and related color flags / positional color arg) only accept either hex colors or CSS color names; a bare value like \"FF0000\" or \"red\" missing the hash goes through this branch when it doesn't match a CSS name either.","triggerScenarios":"Calling `wsh setbg --border-color FF0000` or `wsh setbg red-ish` — a value with no leading '#' that is also not in the CssColorNames map.","commonSituations":"Copy-pasting a hex value without the '#'; forgetting the '#' after shell quoting; supplying an invented color name not in the CSS color list.","solutions":["Prefix the value with '#': `wsh setbg --border-color #FF0000`.","Quote the argument in shells that treat '#' as a comment: `wsh setbg --border-color '#FF0000'`.","Or use a valid CSS color name: `wsh setbg --border-color red`."],"exampleFix":"// before\nwsh setbg --border-color FF0000\n// after\nwsh setbg --border-color '#FF0000'","handlingStrategy":"validation","validationCode":"func isCssColorName(c string) bool { return CssColorNames[strings.ToLower(c)] }\nfunc looksLikeHex(c string) bool { return strings.HasPrefix(c, \"#\") }\n// before calling: if !looksLikeHex(v) && !isCssColorName(v) { fix arg }","typeGuard":"func isValidColorArg(c string) bool {\n    if strings.HasPrefix(c, \"#\") { return len(c) == 7 || len(c) == 9 }\n    return CssColorNames[strings.ToLower(c)]\n}","tryCatchPattern":"if err := validateColor(v); err != nil {\n    if strings.Contains(err.Error(), \"must start with #\") { /* suggest: append '#' or use CSS name */ }\n    return err\n}","preventionTips":["Always quote color arguments in shells so '#' is not treated as a comment.","Prefer hex with explicit '#' or well-known CSS names.","Sanitize pasted values to strip stray whitespace."],"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"}