{"record":{"id":"ce06c837e6ec0323","repo":"JuliusBrussee/caveman","slug":"catalog-is-empty","errorCode":null,"errorMessage":"catalog is empty","messagePattern":"catalog is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/catalog/catalog.go","lineNumber":317,"sourceCode":"// 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}\n\t\tverified, err := time.Parse(time.RFC3339, entry.VerifiedAt)\n\t\tif err != nil || verified.IsZero() {\n\t\t\treturn nil, fmt.Errorf(\"%s %s/%s: verified_at must be RFC3339\", label, entry.Provider, entry.Model)\n\t\t}\n\t\tif verified.After(time.Now().UTC().Add(24 * time.Hour)) {","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/catalog/catalog.go#L299-L335","documentation":"DecodeAndValidate rejects a catalog whose top-level decoded value is empty (no entries decoded). An empty catalog cannot be trusted as routing/pricing truth, so it fails instead of yielding zero entries.","triggerScenarios":"Calling DecodeAndValidate with a YAML file that is empty, whitespace/comment-only, or decodes to a zero-length entry list (e.g. 'entries: []' depending on the target type).","commonSituations":"A catalog file truncated to zero bytes by a failed write, a CI step that overwrote the catalog with nothing, or an env/config pointing at the wrong (empty) file.","solutions":["Restore the real catalog content from version control or the generator.","Check the file is non-empty: wc -c catalog.yaml; fix the pipeline that produced it.","Verify the loader is pointed at the correct catalog path, not a placeholder.","Add a pre-flight non-empty check before load in deployment scripts."],"exampleFix":"# before\ncat > catalog.yaml <<EOF\nEOF\n# after\ncat > catalog.yaml <<EOF\nentries:\n  - provider: anthropic\n    model: claude-sonnet\n    region: us\n    currency: USD\n    ...\nEOF","handlingStrategy":"validation","validationCode":"if len(bytes.TrimSpace(raw)) == 0 {\n\treturn fmt.Errorf(\"catalog file is empty\")\n}","typeGuard":null,"tryCatchPattern":"entries, err := load(path)\nif err != nil {\n\tif strings.Contains(err.Error(), \"catalog is empty\") {\n\t\treturn restoreLastKnownGoodCatalog()\n\t}\n\treturn err\n}","preventionTips":["Check file size before load in deploy scripts","Use atomic writes (temp file + rename) so failed writes can't truncate the catalog","Keep catalogs in version control for easy restore","Alert on any pipeline step that writes a zero-byte catalog"],"tags":["yaml","catalog","empty-input"],"backgroundTag":"empty-required-field","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"}