matryer/xbar · error
invalid named color "%s"
Error message
invalid named color "%s"
What it means
If the color value does not start with '#', parseColor looks it up in the namedColors map. This error means the value is neither a supported hex literal nor a recognized named color. Note the value is lower-cased before lookup, so casing is not the issue.
Source
Thrown at pkg/plugins/item_params.go:302
// parseColor parses the color value given.
// Valid values: named color, #RGB, #RGBA, #RRGGBB, #RRGGBBAA.
// Returns a nice error if it fails.
func parseColor(s string) (string, error) {
if len(s) == 0 {
return "", errors.Errorf("expected hex string or named color") // Probably an error?
}
s = strings.ToLower(s)
if s[0] == '#' {
// Matches #RGB #RGBA #RRGGBB #RRGGBBAA
if !colorRegexp.Match([]byte(s)) {
return "", errors.Errorf(`invalid hex format "%s"`, s)
}
return s, nil
}
hexValue, valid := namedColors[s]
if !valid {
return "", errors.Errorf(`invalid named color "%s"`, s)
}
return hexValue, nil
}
// parseInt parses an int from a string, returning a nice
// error if it fails.
func parseInt(s string) (int, error) {
i, err := strconv.ParseInt(s, 10, 64)
if err != nil {
return 0, errors.Errorf(`expected an int, not "%s"`, s)
}
return int(i), nil
}
// truncate shrinks a string if it's too long.
func truncate(s string, max int) string {
truncated, err := ansi.Truncate(s, max-1)
if err != nil {View on GitHub (pinned to d624239058)
Solutions
- Use one of the library's supported named colors (red, blue, green, black, white, yellow, magenta, cyan, purple, etc.)
- Switch to hex notation, e.g. color=#8A2BE2 for a custom color
- Check spelling of the color name; lookup is case-insensitive but exact-match on the name
Example fix
// before echo "Item | color=rebeccapurple" // not in namedColors // after echo "Item | color=#663399" // equivalent hex
Defensive patterns
Strategy: validation
Validate before calling
var named = map[string]bool{"black":true,"red":true,"green":true,"yellow":true,"blue":true,"magenta":true,"cyan":true,"white":true}
if !strings.HasPrefix(color, "#") && !named[strings.ToLower(color)] {
color = "#" + color // or fall back to a known named color
} Prevention
- Stick to well-known basic color names
- Use hex for anything custom
- Remember rgb()/hsl() notation is not supported — convert to hex
When it happens
Trigger: setValueByKey passes a non-'#' value absent from namedColors — e.g. color=blurple, color=rgb(255,0,0), color=#-less misspellings like color=grey vs an unsupported name, or locale words like color=rouge.
Common situations: Using CSS colors the library doesn't define (rebeccapurple), using rgb()/hsl() notation instead of hex or named colors, typos such as 'rad' or 'bleu'.
Related errors
- expected hex string or named color
- invalid hex format "%s"
- malformed xbar.var format (default not in select options)
- unknown xbar.var type: %s
- no plugin files
AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02).
Data as JSON: /api/errors/205234cc60929c66.
Report an issue: GitHub.