{"record":{"id":"0ec9dee3f6e6fcf1","repo":"mikefarah/yq","slug":"bad-file-v-w-0ec9de","errorCode":null,"errorMessage":"bad file '%v': %w","messagePattern":"bad file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/utils.go","lineNumber":79,"sourceCode":"\tfilename = resolveFilename(filename)\n\terr := decoder.Init(reader)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tinputList := list.New()\n\tvar currentIndex uint\n\n\tfor {\n\t\tcandidateNode, errorReading := decoder.Decode()\n\n\t\tif errors.Is(errorReading, io.EOF) {\n\t\t\tswitch reader := reader.(type) {\n\t\t\tcase *os.File:\n\t\t\t\tsafelyCloseFile(reader)\n\t\t\t}\n\t\t\treturn inputList, nil\n\t\t} else if errorReading != nil {\n\t\t\treturn nil, fmt.Errorf(\"bad file '%v': %w\", filename, errorReading)\n\t\t}\n\t\tcandidateNode.document = currentIndex\n\t\tcandidateNode.filename = filename\n\t\tcandidateNode.fileIndex = fileIndex\n\t\tcandidateNode.EvaluateTogether = true\n\n\t\tinputList.PushBack(candidateNode)\n\n\t\tcurrentIndex = currentIndex + 1\n\t}\n}\n","sourceCodeStart":61,"sourceCodeEnd":91,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/utils.go#L61-L91","documentation":"readDocuments decodes input documents for evaluation (used both by CLI file evaluation and test helpers). A decode error other than io.EOF is reported as `bad file '<filename>': <cause>`, wrapping the underlying parser failure so the user can identify the failing input.","triggerScenarios":"Calling EvaluateFiles (or test helpers like processFormatScenario/assertEncodesTo) with a reader whose contents the decoder cannot parse — invalid YAML/JSON/XML for the configured decoder, or a reader returning a non-EOF error mid-stream.","commonSituations":"Malformed YAML (bad indentation, tabs, duplicate anchors issues), JSON with trailing commas, XML/CSV content fed to the wrong decoder in tests, or read errors from a failing file handle mid-decode.","solutions":["Run the input through a standalone parser (`yq '.' file` or a YAML/JSON linter) to surface the underlying syntax error and fix it","Confirm the decoder/format matches the data (input-format flag or correct format in test scenarios)","Check for tab characters or inconsistent indentation in YAML and reformat","Inspect the wrapped %w cause in the message — it names the exact parse failure"],"exampleFix":"// before\na:\n\tb: 1\n// after\na:\n  b: 1\n","handlingStrategy":"try-catch","validationCode":"// Pre-parse YAML to catch syntax errors before yq decode\nvar n yaml.Node\nif err := yaml.Unmarshal(data, &n); err != nil {\n\treturn fmt.Errorf(\"invalid YAML in %s: %w\", filename, err)\n}","typeGuard":null,"tryCatchPattern":"docs, err := readDocuments(reader, filename, ...)\nif err != nil && strings.HasPrefix(err.Error(), \"bad file '\") {\n\t// surface the wrapped %w cause and fix or skip the file\n}","preventionTips":["Replace tabs with spaces in YAML files","Run YAML/JSON linting in CI on all input documents","Ensure test scenarios pass data matching the configured format decoder","Inspect the wrapped cause in the error message for the exact parse failure"],"tags":["parsing","file-input","decoding"],"backgroundTag":"bad-input-file","analyzedSha":"8b5af0694bb82b41d4ae180fac9972029066f90a","analyzedAt":"2026-09-05T10:57:22.766Z","contentChangedAt":"2026-09-05T10:57:22.766Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}