AlexxIT/go2rtc · error

yaml: path not exist

Error message

yaml: path not exist

What it means

YAML patcher addToEnd guard: the requested path is not exactly two segments (len(path) != 2) or the value is nil. addToEnd can only append a new top.key -> sub.key -> value mapping; deeper or shallower paths cannot be synthesized at end-of-document and are rejected.

Solutions

  1. Restrict patch-add operations to two-level keys (top.sub)
  2. Create intermediate structure in the YAML first, then patch the leaf
  3. Handle nil values upstream instead of calling addToEnd with them
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/yaml/yaml.go:142 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/9c8c9162ebd489e3. Report an issue: GitHub.

Appendix: source

Thrown at pkg/yaml/yaml.go:142

	for i := offset1; i < len(in); {
		indent, length := parseLine(in[i:])
		if indent+1 != length {
			if node.Column < indent+1 {
				offset1 = i + length
			} else {
				break
			}
		}
		i += length
	}

	return
}

func addToEnd(in []byte, path []string, value any) ([]byte, error) {
	if len(path) != 2 || value == nil {
		return nil, errors.New("yaml: path not exist")
	}

	v := map[string]map[string]any{
		path[0]: {path[1]: value},
	}
	paste, err := Encode(v, 2)
	if err != nil {
		return nil, err
	}

	return join(in, paste), nil
}

func join(items ...[]byte) []byte {
	n := len(items) - 1
	for _, b := range items {
		n += len(b)
	}

View on GitHub (pinned to c245815e75)