matryer/xbar · error

invalid hex format "%s"

Error message

invalid hex format "%s"

What it means

When a color value starts with '#', parseColor matches it against colorRegexp which only accepts #RGB, #RGBA, #RRGGBB or #RRGGBBAA. This error means the hex string is present but has an invalid shape — wrong number of digits or illegal hex characters.

Source

Thrown at pkg/plugins/item_params.go:296

	b, err := strconv.ParseBool(s)
	if err != nil {
		return false, errors.Errorf(`expected "true" or "false", not "%s"`, s)
	}
	return b, nil
}

// 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

View on GitHub (pinned to d624239058)

Solutions

  1. Use exactly 3, 4, 6 or 8 hex digits after '#', e.g. #FFF, #FF0000, #FF0000FF
  2. Check for non-hex characters (G-Z) in the value
  3. If using a named color, drop the '#' — named colors must not start with '#'

Example fix

// before
echo "Item | color=#FF"        // 2 digits, invalid
// after
echo "Item | color=#FF0000"    // 6-digit hex
Defensive patterns

Strategy: validation

Validate before calling

var hexRe = regexp.MustCompile(`^#[0-9a-fA-F]{3}([0-9a-fA-F]|[0-9a-fA-F]{3}([0-9a-fA-F])?)?$|^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$`)
if strings.HasPrefix(color, "#") && !hexRe.MatchString(color) {
    color = "#000000" // sanitize before emitting
}

Prevention

When it happens

Trigger: setValueByKey passes a value beginning with '#' that fails colorRegexp — e.g. #FF (too short), #FFFFFFF (7 digits), #GGHHII (non-hex chars), or a stray '#' with nothing after it.

Common situations: Plugin authors writing 3-digit-style shorthand incorrectly (#F0F0), copy-pasting 6-digit colors without '#' handling issues, CSS var(--x) or swatch names accidentally left in place of hex, missing digits after '#'.

Related errors


AI-assisted analysis of matryer/xbar@d624239058 (2026-09-02). Data as JSON: /api/errors/069bc805d1a942a1. Report an issue: GitHub.