kovidgoyal/kitty · error
not a valid color name: %#v
Error message
not a valid color name: %#v
What it means
Raised by ParseColor when the input (trimmed, lowercased) is neither a key in the ColorNames map nor long enough (≥4 chars) to possibly be a structured color. Short strings that aren't known color names can never match any of the structured parsers, so they are rejected immediately.
Source
Thrown at tools/utils/style/wrapper.go:208
if strings.HasPrefix(color, "#") {
// For hex colors, only strip comments after whitespace
parts := strings.Fields(color)
if len(parts) > 0 {
color = parts[0] // Keep only the hex color part
}
} else {
// For non-hex colors, strip everything after #
if idx := strings.Index(color, "#"); idx >= 0 {
color = strings.TrimSpace(color[:idx])
}
}
raw := strings.TrimSpace(strings.ToLower(color))
if val, ok := ColorNames[raw]; ok {
return val, nil
}
if len(raw) < 4 {
return RGBA{}, fmt.Errorf("not a valid color name: %#v", color)
}
var parser func(string) (RGBA, error)
switch raw[0] {
case '#':
parser = parse_sharp
raw = raw[1:]
case 'o':
if strings.HasPrefix(raw, "oklch(") {
parser, raw = parseOklch, raw[6:]
}
case 'l':
if strings.HasPrefix(raw, "lab(") {
parser, raw = parseLab, raw[4:]
}
case 'r':
if len(raw) > 4 && strings.HasPrefix(raw, "rgb") {
raw = raw[3:]
switch raw[0] {View on GitHub (pinned to 6d5d0c4406)
Solutions
- Check for empty/unset color variables before calling ParseColor (e.g. missing env var produced "").
- Use a known color name from ColorNames (red, green, ...) for short values.
- For structured formats, ensure the string is at least 4 characters (e.g. "#fff" + prefix requirements).
- Trim input and log the offending value when the error occurs.
Example fix
// before
col, err := style.ParseColor(os.Getenv("ACCENT")) // ACCENT unset → ""
// after
v := strings.TrimSpace(os.Getenv("ACCENT"))
if v == "" { v = "red" }
col, err := style.ParseColor(v) Defensive patterns
Strategy: validation
Validate before calling
func nonEmptyColorName(s string) bool {
return len(strings.TrimSpace(s)) > 0
} Try / catch
if _, err := style.ParseColor(v); err != nil {
return fmt.Errorf("invalid color %q: %w", v, err)
} Prevention
- Default empty/unset env or config values before parsing.
- Check membership in style.ColorNames for short named colors.
- Trim input at the boundary.
When it happens
Trigger: ParseColor("abc") (3 chars, not a known name), ParseColor(""), ParseColor(" # ") after trimming, or a 1–3 character typo like "rd" instead of "red".
Common situations: Typos in named colors, empty values from unset config/env variables, or strings that were mangled by earlier processing (e.g. comment-stripping removing most of the input).
Related errors
- length not a multiple of 3
- not a valid color name: %#v %w
- Invalid color name: {raw!r}
- invalid rgb numbers
- No kitten named {original_kitten_name}
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/e662fe3003a74fac.
Report an issue: GitHub.