glanceapp/glance · error

compiling theme style: %v

Error message

compiling theme style: %v

What it means

Returned by themeProperties.init() when executing themeStyleTemplate against the theme's properties fails to produce the CSS. The template interpolates all theme fields (colors as HSL, multipliers, ratios); execution errors come from invalid data reaching the template — most often a color field (hslColorField) that decoded into values the template cannot render.

Source

Thrown at internal/glance/theme.go:59

type themeProperties struct {
	BackgroundColor          *hslColorField `yaml:"background-color"`
	PrimaryColor             *hslColorField `yaml:"primary-color"`
	PositiveColor            *hslColorField `yaml:"positive-color"`
	NegativeColor            *hslColorField `yaml:"negative-color"`
	Light                    bool           `yaml:"light"`
	ContrastMultiplier       float32        `yaml:"contrast-multiplier"`
	TextSaturationMultiplier float32        `yaml:"text-saturation-multiplier"`

	Key                  string        `yaml:"-"`
	CSS                  template.CSS  `yaml:"-"`
	PreviewHTML          template.HTML `yaml:"-"`
	BackgroundColorAsHex string        `yaml:"-"`
}

func (t *themeProperties) init() error {
	css, err := executeTemplateToString(themeStyleTemplate, t)
	if err != nil {
		return fmt.Errorf("compiling theme style: %v", err)
	}
	t.CSS = template.CSS(whitespaceAtBeginningOfLinePattern.ReplaceAllString(css, ""))

	previewHTML, err := executeTemplateToString(themePresetPreviewTemplate, t)
	if err != nil {
		return fmt.Errorf("compiling theme preview: %v", err)
	}
	t.PreviewHTML = template.HTML(previewHTML)

	if t.BackgroundColor != nil {
		t.BackgroundColorAsHex = t.BackgroundColor.ToHex()
	} else {
		t.BackgroundColorAsHex = "#151519"
	}

	return nil
}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Read the chained template error for the failing field/expression
  2. Normalize theme values: standard hex/hsl colors, plain numeric multipliers (e.g. 1.2, 0.5)
  3. Reset the theme block to defaults and re-apply changes incrementally to isolate the bad value

Example fix

# before
theme:
  contrast-multiplier: "1.2x"  # non-numeric
# after
theme:
  contrast-multiplier: 1.2
Defensive patterns

Strategy: validation

Validate before calling

// Bounds-check multiplier fields in raw YAML before startup
var t struct{ ContrastMultiplier float32 `yaml:"contrast-multiplier"`; TextSaturationMultiplier float32 `yaml:"text-saturation-multiplier"` }
// decode theme+presets into such probes; reject NaN/Inf or negative values
if math.IsNaN(float64(t.ContrastMultiplier)) || t.ContrastMultiplier < 0 {
    return errors.New("contrast-multiplier must be a non-negative number")
}

Type guard

func validMultiplier(f float32) bool { return !math.IsNaN(float64(f)) && !math.IsInf(float64(f), 0) && f >= 0 }

Try / catch

Catch during theme init and print the chained template error with the theme/preset name; correct the config value — retries cannot succeed.

Prevention

When it happens

Trigger: A theme (preset or default) with color fields that pass YAML decoding but break template rendering: negative or NaN floats in multipliers, or a struct state produced by unusual YAML scalar forms; forks editing themeStyleTemplate add more failure modes.

Common situations: Extreme values for contrast-multiplier/text-saturation-multiplier; unusual color scalar formats that decode oddly; template edits in forks referencing fields that can be zero/nil.

Related errors


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