abiosoft/colima · error

error encoding yaml file: %w

Error message

error encoding yaml file: %w

What it means

encodeYAML (util/yamlutil/yaml.go:106) is the final step: it encodes the modified yaml.Node document back to bytes; this error wraps a failure of that encoder. The yaml encoder over a Node tree fails if the tree is in an invalid state (e.g. a node left without valid kind/content after value replacement) or the underlying writer errors. The earlier steps validate the tree, so this indicates the value-application step left the document malformed — a code bug in node handling rather than bad user config.

Source

Thrown at util/yamlutil/yaml.go:106

		// no performance concern as only one file is being read
		b, err := yaml.Marshal(val)
		if err != nil {
			return nil, fmt.Errorf("unexpected error nested value encoding: %w", err)
		}
		var newNode yaml.Node
		if err := yaml.Unmarshal(b, &newNode); err != nil {
			return nil, fmt.Errorf("unexpected error during yaml node traversal: %w", err)
		}

		if l := len(newNode.Content); l != 1 {
			return nil, fmt.Errorf("unexpected error during yaml node traversal: doc has multiple children of len %d", l)
		}
		*node = *newNode.Content[0]
	}

	b, err := encode(root)
	if err != nil {
		return nil, fmt.Errorf("error encoding yaml file: %w", err)
	}

	return b, nil
}

func traverseConfig(parentKey string, s any, vals map[string]any) {
	typ := reflect.TypeOf(s)
	val := reflect.ValueOf(s)

	// everything else is a value, no nesting required
	if typ.Kind() != reflect.Struct {
		vals[parentKey] = val.Interface()
		return
	}

	// traverse the struct fields recursively
	for i := 0; i < typ.NumField(); i++ {
		field := typ.Field(i)

View on GitHub (pinned to c3a5f9184d)

Solutions

  1. If you maintain a fork, diff your changes in the apply loop against upstream and restore the *node = *newNode.Content[0] assignment semantics
  2. Serialize config saves behind a mutex to rule out concurrent tree mutation
  3. Report upstream with the config that triggered it and the wrapped cause
  4. Reinstall the stock binary and retry with the same config
Defensive patterns

Strategy: try-catch

Try / catch

if err := util.Save(cfg, file); err != nil {
    if strings.Contains(err.Error(), "error encoding yaml file") {
        // node tree left invalid — retry once with a fresh config load; if it
        // persists, the config value types need review
    }
    return err
}

Prevention

When it happens

Trigger: A fork modification of the apply loop (yaml.go:74-102) that assigns a mismatched node kind (e.g. scalar replaced by an empty node) so the final encode chokes; extremely rarely, writer I/O failure on in-memory encode.

Common situations: Forks tampering with how values are merged into the node tree; concurrent config saves mutating the same tree (data race).

Related errors


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