glanceapp/glance · error

HSL hue must be between 0 and %d

Error message

HSL hue must be between 0 and %d

What it means

Returned by hslColorField.UnmarshalYAML when the hue component of an HSL color string parses as a float but exceeds hslHueMax (360). The value matched the syntax pattern, so this is a range check failure specifically on the first component; the message interpolates the max (360).

Source

Thrown at internal/glance/config-fields.go:68

	var value string

	if err := node.Decode(&value); err != nil {
		return err
	}

	matches := hslColorFieldPattern.FindStringSubmatch(value)

	if len(matches) != 4 {
		return fmt.Errorf("invalid HSL color format: %s", value)
	}

	hue, err := strconv.ParseFloat(matches[1], 64)
	if err != nil {
		return err
	}

	if hue > hslHueMax {
		return fmt.Errorf("HSL hue must be between 0 and %d", hslHueMax)
	}

	saturation, err := strconv.ParseFloat(matches[2], 64)
	if err != nil {
		return err
	}

	if saturation > hslSaturationMax {
		return fmt.Errorf("HSL saturation must be between 0 and %d", hslSaturationMax)
	}

	lightness, err := strconv.ParseFloat(matches[3], 64)
	if err != nil {
		return err
	}

	if lightness > hslLightnessMax {
		return fmt.Errorf("HSL lightness must be between 0 and %d", hslLightnessMax)

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Keep hue in the range 0-360 (wrap manually: 370 is equivalent to 10).
  2. Check for accidental extra digits in the first number.
  3. Validate with `glance config:validate` after theme edits.

Example fix

# before
primary-color: 380 60% 50%

# after
primary-color: 20 60% 50%
Defensive patterns

Strategy: validation

Validate before calling

python3 -c "
import re,sys
hsl=re.compile(r'^(\d+(?:\.\d+)?) (\d+(?:\.\d+)?)% (\d+(?:\.\d+)?)%$')
m=hsl.match('370 50% 40%')
sys.exit('hue out of range' if m and float(m.group(1))>360 else 0)
"

Prevention

When it happens

Trigger: An HSL color like `370 50% 40%` or `400 50% 40%` — any hue greater than 360 after strconv.ParseFloat succeeds.

Common situations: Typos adding an extra digit (e.g. 2200); assuming hue wraps around like some CSS implementations; feeding degrees from a calculation that overflowed the 0-360 range.

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/116c8e0012cb9381. Report an issue: GitHub.