{"record":{"id":"f3fe23041d16135f","repo":"antonmedv/fx","slug":"error-from-io-readall-of-input-source-panic-err","errorCode":null,"errorMessage":"<error from io.ReadAll of input source> (panic(err))","messagePattern":"<error from io\\.ReadAll of input source> \\(panic\\(err\\)\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"main.go","lineNumber":195,"sourceCode":"\t\t} else {\n\t\t\t// $ fx file.json arg*\n\t\t\tfilePath := args[0]\n\t\t\tsrc = open(filePath, &flagYaml, &flagToml)\n\t\t\tengine.FilePath = filePath\n\t\t\tfileName = filepath.Base(filePath)\n\t\t\targs = args[1:]\n\t\t}\n\t} else {\n\t\t// cat file.json | fx arg*\n\t\tsrc = os.Stdin\n\t}\n\n\tvar parser engine.Parser\n\n\tif flagYaml {\n\t\tb, err := io.ReadAll(src)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tjsonBytes, err := parseYAML(b)\n\t\tif err != nil {\n\t\t\tfmt.Print(err.Error())\n\t\t\tos.Exit(1)\n\t\t\treturn\n\t\t}\n\t\tparser = NewJsonParser(bytes.NewReader(jsonBytes), flagStrict)\n\t} else if flagToml {\n\t\tb, err := io.ReadAll(src)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tjsonBytes, err := toml.ToJSON(b)\n\t\tif err != nil {\n\t\t\tfmt.Print(err.Error())\n\t\t\tos.Exit(1)\n\t\t\treturn","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/main.go#L177-L213","documentation":"When the --yaml flag is set, main reads the entire input source with io.ReadAll before handing it to parseYAML. If the read itself fails (I/O error, broken pipe, reader already consumed), the program panics with the raw error. This is an unrecoverable infrastructure failure, distinct from YAML parse errors which are printed and exit(1).","triggerScenarios":"io.ReadAll(src) returns a non-nil error while reading stdin or an opened file — e.g. reading from a closed pipe, a device that errors mid-read, or a reader consumed by a previous pass.","commonSituations":"Piping input from a command that dies mid-stream; reading from a special file or network stream that fails; stdin closed before data is written.","solutions":["Check that the upstream data source (file, pipe) is readable and complete before running fx","Re-run the command; transient read failures (network fs, flaky pipe) may succeed on retry","Wrap the source in a buffered reader or read to a temp file first so failures surface before parsing"],"exampleFix":"// before\nb, err := io.ReadAll(src)\nif err != nil {\n\tpanic(err)\n}\n// after\nb, err := io.ReadAll(src)\nif err != nil {\n\tfmt.Fprintf(os.Stderr, \"failed to read input: %v\\n\", err)\n\tos.Exit(1)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// recover around a programmatic invocation of fx\nfunc runFX(args []string) (err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"fx panicked reading input: %v\", r)\n\t\t}\n\t}()\n\treturn callMain(args)\n}","preventionTips":["Check upstream process exit codes before piping into fx","Ensure stdin is a complete, readable stream (avoid closing pipes early)","For critical data, write to a temp file first and pass the path"],"tags":["go","panic","io","yaml","stdin"],"backgroundTag":"io-read-failed","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}