{"record":{"id":"42e8a3d9eb4c98a9","repo":"glanceapp/glance","slug":"creating-theme-presets-v","errorCode":null,"errorMessage":"creating theme presets: %v","messagePattern":"creating theme presets: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/glance.go","lineNumber":126,"sourceCode":"\t\tdefaultDarkTheme, ok := config.Theme.Presets.Get(\"default-dark\")\n\t\tif ok && !config.Theme.SameAs(defaultDarkTheme) || !config.Theme.SameAs(&themeProperties{}) {\n\t\t\tthemeKeys = append(themeKeys, \"default-dark\")\n\t\t\tthemeProps = append(themeProps, &themeProperties{})\n\t\t}\n\n\t\tthemeKeys = append(themeKeys, \"default-light\")\n\t\tthemeProps = append(themeProps, &themeProperties{\n\t\t\tLight:                    true,\n\t\t\tBackgroundColor:          &hslColorField{240, 13, 95},\n\t\t\tPrimaryColor:             &hslColorField{230, 100, 30},\n\t\t\tNegativeColor:            &hslColorField{0, 70, 50},\n\t\t\tContrastMultiplier:       1.3,\n\t\t\tTextSaturationMultiplier: 0.5,\n\t\t})\n\n\t\tthemePresets, err := newOrderedYAMLMap(themeKeys, themeProps)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"creating theme presets: %v\", err)\n\t\t}\n\t\tconfig.Theme.Presets = *themePresets.Merge(&config.Theme.Presets)\n\n\t\tfor key, properties := range config.Theme.Presets.Items() {\n\t\t\tproperties.Key = key\n\t\t\tif err := properties.init(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"initializing preset theme %s: %v\", key, err)\n\t\t\t}\n\t\t}\n\t}\n\n\tconfig.Theme.Key = \"default\"\n\tif err := config.Theme.init(); err != nil {\n\t\treturn nil, fmt.Errorf(\"initializing default theme: %v\", err)\n\t}\n\n\t//\n\t// Init pages","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/glance.go#L108-L144","documentation":"Startup fails when newOrderedYAMLMap cannot build the built-in theme preset map. Internally that constructor errors when the keys and values slices have different lengths; since both slices are hardcoded literals in glance.go (light/dark presets), a mismatch means the source was edited inconsistently or the function was reused with mismatched slices in a fork/plugin.","triggerScenarios":"Calling newOrderedYAMLMap(themeKeys, themeProps) with len(themeKeys) != len(themeProps), or modifying the hardcoded preset lists in glance.go and adding a key without a matching properties entry.","commonSituations":"Fork maintainers adding a new built-in theme preset and forgetting the matching themeProperties entry; reusing newOrderedYAMLMap elsewhere with slices built by separate loops.","solutions":["If you edited the preset lists, make every key in themeKeys have exactly one entry in themeProps at the same index","If using newOrderedYAMLMap in your own code, build both slices from a single source (one loop, or key/value pairs) so they cannot diverge","Diff against upstream glance to find the accidental asymmetry"],"exampleFix":"// before (fork edit gone wrong)\nthemeKeys = append(themeKeys, \"default-light\")\n// forgot: themeProps = append(themeProps, &themeProperties{...})\n// after\nthemeKeys = append(themeKeys, \"default-light\")\nthemeProps = append(themeProps, &themeProperties{Light: true})\n","handlingStrategy":"validation","validationCode":"// Guard the constructor invariant in your own code\nif len(keys) != len(values) {\n    return nil, fmt.Errorf(\"keys/values length mismatch: %d vs %d\", len(keys), len(values))\n}\n","typeGuard":null,"tryCatchPattern":"For fork/plugin code calling newOrderedYAMLMap, validate slice lengths first; in stock glance this error indicates a source edit — fix the edit, not a runtime catch.","preventionTips":["Build key/value slices in one loop","Add a unit test asserting len(themeKeys)==len(themeProps) when editing presets","Keep preset key/property additions paired in the same commit"],"tags":["themes","internal","startup"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}