JuliusBrussee/caveman · error
multiple YAML documents are not allowed
Error message
multiple YAML documents are not allowed
What it means
DecodeAndValidate uses a YAML decoder repeatedly and rejects input that contains more than one YAML document (i.e. multiple '---' separated documents). This keeps catalogs unambiguous — a multi-doc file would silently decode only its first document.
Solutions
- Open the catalog file and remove the extra '---' separator and everything after it, keeping a single document.
- Split genuinely separate catalogs into separate files.
- Strip a leading/extra '---' if the file was machine-templated with multiple docs.
- Re-run DecodeAndValidate to confirm only one document remains.
Example fix
// before (catalog.yaml) --- entries: - provider: a --- entries: - provider: b // after entries: - provider: a - provider: b
Defensive patterns
Strategy: validation
Validate before calling
docs := strings.Count(string(raw), "\n---")
if docs > 0 && strings.TrimSpace(strings.SplitN(string(raw), "\n---", 2)[1]) != "" {
return fmt.Errorf("catalog file has multiple YAML documents")
} Try / catch
if _, err := catalog.DecodeAndValidate(raw); err != nil {
if strings.Contains(err.Error(), "multiple YAML documents") {
return fmt.Errorf("split or concatenate catalog into one document: %w", err)
}
return err
} Prevention
- Avoid 'cat a.yaml b.yaml' style concatenation of catalogs
- Strip template separators ('---') after rendering templates
- Lint catalogs for multiple documents in CI
When it happens
Trigger: Calling DecodeAndValidate (via load, loadCurrentCatalog, snapshotDrift) with YAML containing a second document, i.e. a second '---' separator followed by more content.
Common situations: Concatenating catalog files with 'cat a.yaml b.yaml > catalog.yaml', copy-paste that included a document separator, or templates that emit '---' headers between resources.
Related errors
- catalog is empty
- catalog
- : currency must be USD
- : must be a safe non-empty identifier
- : missing field(s)
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/1638bc8568b0bbe9.
Report an issue: GitHub.
Appendix: 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 3ee70a1026)