{"record":{"id":"29448e468d3c4c02","repo":"mikefarah/yq","slug":"bad-file-v-w","errorCode":null,"errorMessage":"bad file '%v': %w","messagePattern":"bad file '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/yqlib/stream_evaluator.go","lineNumber":88,"sourceCode":"\treturn nil\n}\n\nfunc (s *streamEvaluator) Evaluate(filename string, reader io.Reader, node *ExpressionNode, printer Printer, decoder Decoder) (uint, error) {\n\tfilename = resolveFilename(filename)\n\n\tvar currentIndex uint\n\terr := decoder.Init(reader)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tfor {\n\t\tcandidateNode, errorReading := decoder.Decode()\n\n\t\tif errors.Is(errorReading, io.EOF) {\n\t\t\ts.fileIndex = s.fileIndex + 1\n\t\t\treturn currentIndex, nil\n\t\t} else if errorReading != nil {\n\t\t\treturn currentIndex, 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 = s.fileIndex\n\n\t\tinputList := list.New()\n\t\tinputList.PushBack(candidateNode)\n\n\t\tresult, errorParsing := s.treeNavigator.GetMatchingNodes(Context{MatchingNodes: inputList}, node)\n\t\tif errorParsing != nil {\n\t\t\treturn currentIndex, errorParsing\n\t\t}\n\t\terr := printer.PrintResults(result.MatchingNodes)\n\n\t\tif err != nil {\n\t\t\treturn currentIndex, err\n\t\t}\n\t\tcurrentIndex = currentIndex + 1","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/mikefarah/yq/blob/8b5af0694bb82b41d4ae180fac9972029066f90a/pkg/yqlib/stream_evaluator.go#L70-L106","documentation":"The stream evaluator decodes documents one at a time from each input file. Any decode error other than io.EOF is wrapped as `bad file '<filename>': <cause>` so the user knows which file failed to parse. This does not indicate a yq bug, but malformed input for the selected decoder.","triggerScenarios":"Running `yq eval-files` (or a multi-file evaluation) where one of the input files is not valid for the chosen input format — e.g. malformed XML/JSON/CSV passed to the XML/JSON decoder — so decoder.Decode() returns a non-EOF error.","commonSituations":"Passing a file with the wrong extension/format flag (JSON content parsed as XML), truncated downloads, files with BOM or encoding issues, or empty/corrupt files in a glob-expanded list.","solutions":["Validate the offending file with a format-specific parser (e.g. `xmllint --noout`, `jq . file`) and fix the syntax error","Ensure the input format flag (`-p`/`--input-format`) matches the actual file contents","Check file encoding — strip BOM or convert to UTF-8 if the decoder chokes on it","Re-download or restore the corrupted file"],"exampleFix":"// before\nyq -p=json eval '.a' data.xml\n// after\nyq -p=xml eval '.a' data.xml\n","handlingStrategy":"try-catch","validationCode":"// Validate the file parses with the expected decoder before evaluation\ndata, _ := os.ReadFile(filename)\nif json.Valid(data) && inputFormat == \"xml\" {\n\treturn fmt.Errorf(\"%s looks like JSON but input-format is xml\", filename)\n}","typeGuard":null,"tryCatchPattern":"results, err := evaluator.EvaluateFiles(filenames, ...)\nif err != nil {\n\tvar badFileErr error\n\tif strings.HasPrefix(err.Error(), \"bad file '\") {\n\t\t// extract filename, log, and skip or fail per file\n\t}\n\treturn err\n}","preventionTips":["Match --input-format to actual file contents","Validate each input file with a format-specific linter before batch runs","Check encodings (strip BOM, use UTF-8)","Guard glob-expanded file lists against non-conforming files"],"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"}