abiosoft/colima · error

uneven children of %d found for mapping node

Error message

uneven children of %d found for mapping node

What it means

traverseNode (util/yamlutil/yaml.go:144) enforces YAML's structural rule while walking the embedded default: a mapping node's Content list alternates key, value, key, value, so its length must be even. An odd length means a key with no value — malformed mapping content that strict unmarshal would normally have rejected earlier, so this is defense-in-depth over the embedded asset. It propagates up to callers as 'error traversing yaml node' (error 293).

Source

Thrown at util/yamlutil/yaml.go:144

		if key == "" || key == "-" { // no yaml tag is present
			continue
		}

		if parentKey != "" {
			key = parentKey + "." + key
		}
		val := val.Field(i)

		traverseConfig(key, val.Interface(), vals)
	}

}

func traverseNode(parentKey string, node *yaml.Node, vals map[string]*yaml.Node) error {
	switch node.Kind {
	case yaml.MappingNode:
		if l := len(node.Content); l%2 != 0 {
			return fmt.Errorf("uneven children of %d found for mapping node", l)
		}
		for i := 0; i < len(node.Content); i += 2 {
			if i > 1 {
				// fix jumbled comments
				if cn := node.Content[i]; cn.HeadComment != "" {
					if strings.Index(cn.HeadComment, "#") == 0 {
						cn.HeadComment = "\n" + cn.HeadComment
					}
				}
			}

			key := node.Content[i].Value
			val := node.Content[i+1]
			if parentKey != "" {
				key = parentKey + "." + key
			}
			vals[key] = val

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. Run the defaults file through a strict YAML linter and fix the reported unbalanced mapping
  2. Restore embedded/defaults/colima.yaml from upstream git and reapply edits
  3. Change defaults via colima's config layer instead of the embedded template
  4. Add CI that round-trips Save() over defaults to catch structural breakage

Example fix

# before
mounts:
  - location

# after
mounts:
  - location: /mnt/data
Defensive patterns

Strategy: validation

Validate before calling

// structural check for mapping nodes before traversal
func mappingBalanced(n *yaml.Node) bool {
    return n.Kind != yaml.MappingNode || len(n.Content)%2 == 0
}

Try / catch

if err := util.Save(cfg, file); err != nil {
    if strings.Contains(err.Error(), "uneven children") {
        // embedded default has a dangling key — restore the asset / reinstall
        return fmt.Errorf("colima defaults structurally broken — reinstall: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: An embedded/defaults/colima.yaml whose mapping content is unbalanced after hand edits (a value deleted but its key left, or vice versa), only reachable when the earlier unmarshal leniently accepted the document as a raw Node.

Common situations: Fork edits and scripted rewrites of the defaults file; merge conflicts resolved by deleting lines; YAML reformatters with bugs producing dangling keys.

Related errors


AI-assisted analysis of abiosoft/colima@c3a5f9184d (2026-08-15). Data as JSON: /api/errors/f5dee88478658c17. Report an issue: GitHub.