{"record":{"id":"fc4e619eef2fe87d","repo":"glanceapp/glance","slug":"compiling-theme-style-v","errorCode":null,"errorMessage":"compiling theme style: %v","messagePattern":"compiling theme style: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/theme.go","lineNumber":59,"sourceCode":"type themeProperties struct {\n\tBackgroundColor          *hslColorField `yaml:\"background-color\"`\n\tPrimaryColor             *hslColorField `yaml:\"primary-color\"`\n\tPositiveColor            *hslColorField `yaml:\"positive-color\"`\n\tNegativeColor            *hslColorField `yaml:\"negative-color\"`\n\tLight                    bool           `yaml:\"light\"`\n\tContrastMultiplier       float32        `yaml:\"contrast-multiplier\"`\n\tTextSaturationMultiplier float32        `yaml:\"text-saturation-multiplier\"`\n\n\tKey                  string        `yaml:\"-\"`\n\tCSS                  template.CSS  `yaml:\"-\"`\n\tPreviewHTML          template.HTML `yaml:\"-\"`\n\tBackgroundColorAsHex string        `yaml:\"-\"`\n}\n\nfunc (t *themeProperties) init() error {\n\tcss, err := executeTemplateToString(themeStyleTemplate, t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"compiling theme style: %v\", err)\n\t}\n\tt.CSS = template.CSS(whitespaceAtBeginningOfLinePattern.ReplaceAllString(css, \"\"))\n\n\tpreviewHTML, err := executeTemplateToString(themePresetPreviewTemplate, t)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"compiling theme preview: %v\", err)\n\t}\n\tt.PreviewHTML = template.HTML(previewHTML)\n\n\tif t.BackgroundColor != nil {\n\t\tt.BackgroundColorAsHex = t.BackgroundColor.ToHex()\n\t} else {\n\t\tt.BackgroundColorAsHex = \"#151519\"\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/theme.go#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the chained template error for the failing field/expression","Normalize theme values: standard hex/hsl colors, plain numeric multipliers (e.g. 1.2, 0.5)","Reset the theme block to defaults and re-apply changes incrementally to isolate the bad value"],"exampleFix":"# before\ntheme:\n  contrast-multiplier: \"1.2x\"  # non-numeric\n# after\ntheme:\n  contrast-multiplier: 1.2\n","handlingStrategy":"validation","validationCode":"// Bounds-check multiplier fields in raw YAML before startup\nvar t struct{ ContrastMultiplier float32 `yaml:\"contrast-multiplier\"`; TextSaturationMultiplier float32 `yaml:\"text-saturation-multiplier\"` }\n// decode theme+presets into such probes; reject NaN/Inf or negative values\nif math.IsNaN(float64(t.ContrastMultiplier)) || t.ContrastMultiplier < 0 {\n    return errors.New(\"contrast-multiplier must be a non-negative number\")\n}\n","typeGuard":"func validMultiplier(f float32) bool { return !math.IsNaN(float64(f)) && !math.IsInf(float64(f), 0) && f >= 0 }","tryCatchPattern":"Catch during theme init and print the chained template error with the theme/preset name; correct the config value — retries cannot succeed.","preventionTips":["Use plain numeric literals for multipliers","Stick to documented color formats","Lint theme blocks with a small YAML schema in CI"],"tags":["themes","template","css","validation"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}