glanceapp/glance · error

orderedMap: duplicate key %v

Error message

orderedMap: duplicate key %v

What it means

The orderedYAMLMap unmarshaler detected the same key appearing twice in one YAML mapping. Because orderedYAMLMap preserves insertion order and stores entries in a Go map, a duplicate key would be ambiguous and data-lossy, so it rejects the document instead of silently overwriting like a plain Go map would.

Source

Thrown at internal/glance/config.go:624

	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)
		}

		var value V
		if err := valueNode.Decode(&value); err != nil {
			return fmt.Errorf("orderedMap: decoding value: %v", err)
		}

		(*om).keys[i/2] = key
		(*om).data[key] = value
	}

	return nil
}

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Search the config (including included files) for the duplicated key printed in the error and remove or rename one occurrence
  2. If merging configs via includes, ensure each key is defined in only one source or intentionally overridden once
  3. Use a YAML linter that flags duplicate keys (yamllint key-duplicates rule)

Example fix

# before
theme:
  presets:
    dark:
      color-scheme: dark
    dark:
      contrast-multiplier: 1.2
# after
theme:
  presets:
    dark:
      color-scheme: dark
      contrast-multiplier: 1.2
Defensive patterns

Strategy: validation

Validate before calling

// Detect duplicate keys in a mapping node before decode
func noDuplicateKeys(n *yaml.Node) error {
    if n.Kind != yaml.MappingNode { return nil }
    seen := map[string]bool{}
    for i := 0; i < len(n.Content); i += 2 {
        k := n.Content[i].Value
        if seen[k] { return fmt.Errorf("duplicate key %q at line %d", k, n.Content[i].Line) }
        seen[k] = true
    }
    return nil
}

Try / catch

On this error, report the duplicated key name (it is in the message) and the file, then fail fast — do not retry.

Prevention

When it happens

Trigger: A single YAML mapping used as a theme preset list, widget options map, or similar contains the same key twice, e.g. two `my-theme:` entries under `theme.presets`, or two identical page names producing the same key.

Common situations: Duplicated blocks after copy-paste; multiple config files merged (glance's parseYAMLIncludes) that define the same key; YAML anchors that unintentionally repeat a key when interpolated.

Related errors


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