{"record":{"id":"1638bc8568b0bbe9","repo":"JuliusBrussee/caveman","slug":"multiple-yaml-documents-are-not-allowed","errorCode":null,"errorMessage":"multiple YAML documents are not allowed","messagePattern":"multiple YAML documents are not allowed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/catalog/catalog.go","lineNumber":312,"sourceCode":"\t\tloadErr = fmt.Errorf(\"catalog %s: %w\", path, err)\n\t}\n\tentries = []Entry{}\n}\n\n// DecodeAndValidate strictly parses a catalog. Unknown YAML fields, duplicate\n// provider/model/region rows, invalid URLs/timestamps, and unsafe prices reject\n// the entire file; runtime must never load a plausible partial catalog.\nfunc DecodeAndValidate(raw []byte) ([]Entry, error) {\n\tdec := yaml.NewDecoder(bytes.NewReader(raw))\n\tdec.KnownFields(true)\n\tvar decoded []Entry\n\tif err := dec.Decode(&decoded); err != nil {\n\t\treturn nil, err\n\t}\n\tvar trailing any\n\tif err := dec.Decode(&trailing); err != io.EOF {\n\t\tif err == nil {\n\t\t\treturn nil, fmt.Errorf(\"multiple YAML documents are not allowed\")\n\t\t}\n\t\treturn nil, err\n\t}\n\tif len(decoded) == 0 {\n\t\treturn nil, fmt.Errorf(\"catalog is empty\")\n\t}\n\tseen := make(map[string]struct{}, len(decoded))\n\tfor i, entry := range decoded {\n\t\tlabel := fmt.Sprintf(\"entry %d\", i)\n\t\tif strings.TrimSpace(entry.Provider) == \"\" || strings.TrimSpace(entry.Model) == \"\" || strings.TrimSpace(entry.Region) == \"\" {\n\t\t\treturn nil, fmt.Errorf(\"%s: provider, model, and region are required\", label)\n\t\t}\n\t\tif entry.Currency != \"USD\" {\n\t\t\treturn nil, fmt.Errorf(\"%s %s/%s: unsupported currency %q\", label, entry.Provider, entry.Model, entry.Currency)\n\t\t}\n\t\tif !cost.ValidPrice(entry.Pricing) {\n\t\t\treturn nil, fmt.Errorf(\"%s %s/%s: invalid pricing\", label, entry.Provider, entry.Model)\n\t\t}","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/catalog/catalog.go#L294-L330","documentation":"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.","triggerScenarios":"Calling DecodeAndValidate (via load, loadCurrentCatalog, snapshotDrift) with YAML containing a second document, i.e. a second '---' separator followed by more content.","commonSituations":"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.","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."],"exampleFix":"// before (catalog.yaml)\n---\nentries:\n  - provider: a\n---\nentries:\n  - provider: b\n// after\nentries:\n  - provider: a\n  - provider: b","handlingStrategy":"validation","validationCode":"docs := strings.Count(string(raw), \"\\n---\")\nif docs > 0 && strings.TrimSpace(strings.SplitN(string(raw), \"\\n---\", 2)[1]) != \"\" {\n\treturn fmt.Errorf(\"catalog file has multiple YAML documents\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := catalog.DecodeAndValidate(raw); err != nil {\n\tif strings.Contains(err.Error(), \"multiple YAML documents\") {\n\t\treturn fmt.Errorf(\"split or concatenate catalog into one document: %w\", err)\n\t}\n\treturn err\n}","preventionTips":["Avoid 'cat a.yaml b.yaml' style concatenation of catalogs","Strip template separators ('---') after rendering templates","Lint catalogs for multiple documents in CI"],"tags":["yaml","catalog","multiple-documents"],"backgroundTag":"yaml-parse-error","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}