JuliusBrussee/caveman · error

multiple YAML documents are not allowed

Error message

multiple YAML documents are not allowed

What it means

Strict-parsing guard in DecodeAndValidate: a second YAML document followed the first in the catalog file. A catalog must be exactly one document so a plausible partial load can never happen; the file contents are at fault.

Source

Thrown at shared/platform/catalog/catalog.go:312

		loadErr = fmt.Errorf("catalog %s: %w", path, err)
	}
	entries = []Entry{}
}

// DecodeAndValidate strictly parses a catalog. Unknown YAML fields, duplicate
// provider/model/region rows, invalid URLs/timestamps, and unsafe prices reject
// the entire file; runtime must never load a plausible partial catalog.
func DecodeAndValidate(raw []byte) ([]Entry, error) {
	dec := yaml.NewDecoder(bytes.NewReader(raw))
	dec.KnownFields(true)
	var decoded []Entry
	if err := dec.Decode(&decoded); err != nil {
		return nil, err
	}
	var trailing any
	if err := dec.Decode(&trailing); err != io.EOF {
		if err == nil {
			return nil, fmt.Errorf("multiple YAML documents are not allowed")
		}
		return nil, err
	}
	if len(decoded) == 0 {
		return nil, fmt.Errorf("catalog is empty")
	}
	seen := make(map[string]struct{}, len(decoded))
	for i, entry := range decoded {
		label := fmt.Sprintf("entry %d", i)
		if strings.TrimSpace(entry.Provider) == "" || strings.TrimSpace(entry.Model) == "" || strings.TrimSpace(entry.Region) == "" {
			return nil, fmt.Errorf("%s: provider, model, and region are required", label)
		}
		if entry.Currency != "USD" {
			return nil, fmt.Errorf("%s %s/%s: unsupported currency %q", label, entry.Provider, entry.Model, entry.Currency)
		}
		if !cost.ValidPrice(entry.Pricing) {
			return nil, fmt.Errorf("%s %s/%s: invalid pricing", label, entry.Provider, entry.Model)
		}

View on GitHub (pinned to 2f49f0e1a3)

Solutions

  1. Split multi-document YAML into a single document containing all entries
  2. Remove accidental '---' separators that create extra documents
  3. Regenerate the catalog with a serializer that emits one document
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at shared/platform/catalog/catalog.go:253 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@2f49f0e1a3 (2026-08-18). Data as JSON: /api/errors/1638bc8568b0bbe9. Report an issue: GitHub.