glanceapp/glance · error

initializing preset theme %s: %v

Error message

initializing preset theme %s: %v

What it means

Startup fails when themeProperties.init() errors for a user-defined theme preset from config.Theme.Presets. init() compiles the theme style and preview templates and validates color fields, so the underlying cause (chained via %v) is typically a template execution failure or an invalid color value in the preset.

Source

Thrown at internal/glance/glance.go:133

		themeProps = append(themeProps, &themeProperties{
			Light:                    true,
			BackgroundColor:          &hslColorField{240, 13, 95},
			PrimaryColor:             &hslColorField{230, 100, 30},
			NegativeColor:            &hslColorField{0, 70, 50},
			ContrastMultiplier:       1.3,
			TextSaturationMultiplier: 0.5,
		})

		themePresets, err := newOrderedYAMLMap(themeKeys, themeProps)
		if err != nil {
			return nil, fmt.Errorf("creating theme presets: %v", err)
		}
		config.Theme.Presets = *themePresets.Merge(&config.Theme.Presets)

		for key, properties := range config.Theme.Presets.Items() {
			properties.Key = key
			if err := properties.init(); err != nil {
				return nil, fmt.Errorf("initializing preset theme %s: %v", key, err)
			}
		}
	}

	config.Theme.Key = "default"
	if err := config.Theme.init(); err != nil {
		return nil, fmt.Errorf("initializing default theme: %v", err)
	}

	//
	// Init pages
	//

	app.slugToPage[""] = &config.Pages[0]

	providers := &widgetProviders{
		assetResolver: app.StaticAssetPath,
	}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Read the chained error: it identifies the failing field or template expression
  2. Check every color field in the failing preset uses the documented format (e.g. `#1a1a1a`, hsl tuples, named values allowed by hslColorField decoding)
  3. Simplify: comment out preset fields until it starts, then re-add the offending field corrected

Example fix

# before
theme:
  presets:
    my-theme:
      color-scheme: lite
# after
theme:
  presets:
    my-theme:
      color-scheme: light
Defensive patterns

Strategy: validation

Validate before calling

// Quick config sanity for preset fields (Go)
var probe struct{ Theme struct{ Presets map[string]struct{ ColorScheme string `yaml:"color-scheme"` } `yaml:"presets"` } `yaml:"theme"` }
if err := yaml.Unmarshal(cfg, &probe); err != nil { return err }
for name, p := range probe.Theme.Presets {
    if p.ColorScheme != "" && p.ColorScheme != "light" && p.ColorScheme != "dark" {
        return fmt.Errorf("preset %s: color-scheme must be light or dark", name)
    }
}

Type guard

func validColorScheme(s string) bool { return s == "" || s == "light" || s == "dark" }

Try / catch

Catch during startup, extract the preset name from the message plus the chained cause, and reject the config with both pieces of context.

Prevention

When it happens

Trigger: Defining a custom preset under `theme.presets` with a malformed `color-scheme`, an invalid HSL/RGB/hex value in background-color/primary-color/negative-color, or fields that break the theme template (e.g. non-numeric multipliers).

Common situations: Typos in color hex strings, color-scheme values other than light/dark, setting contrast-multiplier/text-saturation-multiplier to strings or out-of-format values; presets written for an older glance version with renamed fields.

Related errors


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