antonmedv/fx · error
<error from io.ReadAll of input source> (panic(err))
Error message
<error from io.ReadAll of input source> (panic(err))
What it means
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).
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
Example fix
// before
b, err := io.ReadAll(src)
if err != nil {
panic(err)
}
// after
b, err := io.ReadAll(src)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read input: %v\n", err)
os.Exit(1)
} Defensive patterns
Strategy: try-catch
Try / catch
// recover around a programmatic invocation of fx
func runFX(args []string) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("fx panicked reading input: %v", r)
}
}()
return callMain(args)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- <error from json.Marshal of the theme export map>…
- <error returned from pipeline p.Run()> (panic(err))
- <non-PathError from os.Open(filePath)> (panic(err))
- <panics with the raw TOML input bytes (in) when…
- unsupported node kind
AI-assisted analysis of antonmedv/fx@4f31cd3a0c (2026-09-02).
Data as JSON: /api/errors/f3fe23041d16135f.
Report an issue: GitHub.
Appendix: source
Thrown at main.go:195
} else {
// $ fx file.json arg*
filePath := args[0]
src = open(filePath, &flagYaml, &flagToml)
engine.FilePath = filePath
fileName = filepath.Base(filePath)
args = args[1:]
}
} else {
// cat file.json | fx arg*
src = os.Stdin
}
var parser engine.Parser
if flagYaml {
b, err := io.ReadAll(src)
if err != nil {
panic(err)
}
jsonBytes, err := parseYAML(b)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
return
}
parser = NewJsonParser(bytes.NewReader(jsonBytes), flagStrict)
} else if flagToml {
b, err := io.ReadAll(src)
if err != nil {
panic(err)
}
jsonBytes, err := toml.ToJSON(b)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
returnView on GitHub (pinned to 4f31cd3a0c)