glanceapp/glance · error
orderedMap: expected even number of content items, got %d
Error message
orderedMap: expected even number of content items, got %d
What it means
This error is returned by the custom orderedYAMLMap unmarshaler when a YAML mapping node contains an odd number of content items. In go-yaml, a MappingNode's Content slice always alternates key/value pairs, so an odd length means the YAML document itself is structurally malformed (e.g. a key with no value). It is essentially a defensive sanity check that fires before the key/value decode loop runs.
Source
Thrown at internal/glance/config.go:608
maps.Copy(merged.data, self.data)
for _, key := range other.keys {
if _, exists := self.data[key]; !exists {
merged.keys = append(merged.keys, key)
}
}
maps.Copy(merged.data, other.data)
return merged
}
func (om *orderedYAMLMap[K, V]) UnmarshalYAML(node *yaml.Node) error {
if node.Kind != yaml.MappingNode {
return fmt.Errorf("orderedMap: expected mapping node, got %d", node.Kind)
}
if len(node.Content)%2 != 0 {
return fmt.Errorf("orderedMap: expected even number of content items, got %d", len(node.Content))
}
om.keys = make([]K, len(node.Content)/2)
om.data = make(map[K]V, len(node.Content)/2)
for i := 0; i < len(node.Content); i += 2 {
keyNode := node.Content[i]
valueNode := node.Content[i+1]
var key K
if err := keyNode.Decode(&key); err != nil {
return fmt.Errorf("orderedMap: decoding key: %v", err)
}
if _, ok := om.data[key]; ok {
return fmt.Errorf("orderedMap: duplicate key %v", key)
}
View on GitHub (pinned to 91324e8de7)
Solutions
- Check the config file near the mapping reported in the surrounding error for a key without a value and add the missing value or remove the key
- Validate the YAML with a linter or `glance config-check`/re-parse with a strict YAML tool before running the app
- If generating YAML programmatically, ensure every emitted key also emits a value node
Example fix
# before
theme:
presets:
my-theme:
# after
theme:
presets:
my-theme:
color-scheme: dark
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate config YAML structure before passing to glance
import "gopkg.in/yaml.v3"
func mappingIsBalanced(src []byte) error {
var v any
if err := yaml.Unmarshal(src, &v); err != nil {
return err // syntax error surfaces here first
}
return nil
}
Try / catch
Catch the error at config load and surface file/line from the wrapped yaml error, then re-prompt the user/editor for a corrected file rather than retrying.
Prevention
- Lint YAML in CI with yamllint before deploying
- Never hand-truncate mapping blocks; delete whole key/value pairs
- Use editor YAML language servers that flag structural errors on save
When it happens
Trigger: Unmarshalling any YAML mapping into an orderedYAMLMap field (theme presets, config maps) where the parsed node.Content has odd length. This only occurs with a corrupted YAML document or a malformed node produced by custom decoding logic, since go-yaml itself rejects odd mappings at parse time.
Common situations: Hand-edited glance.yml with a truncated mapping (e.g. a theme preset key with no properties), config files with unbalanced merge keys, or programmatic YAML generation that drops a value node.
Related errors
- URL is required
- nested groups are not supported
- split columns inside of groups are not supported
- source is required
- subreddit is required
AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15).
Data as JSON: /api/errors/c2d81fae648090ed.
Report an issue: GitHub.