facebook/flow · error
failed to read input file
Error message
failed to read input file
What it means
When --input-file points at a real file, get_filenames_from_input slurps it with std::fs::read_to_string. The .expect() panics when the path does not exist (ENOENT), is not readable (EACCES), is a directory (EISDIR), or its content is not valid UTF-8. Notably this missing-file case is not routed through the friendly 'File not found' exit used elsewhere — it crashes instead.
Source
Thrown at rust_port/crates/flow_cli/src/command_utils.rs:142
if allow_imaginary {
flow_common::files::imaginary_realpath(filename)
} else {
let msg = format!("File not found: {:?}", filename);
flow_common_exit::exit(FlowExitStatus::NoInput, Some(&msg));
}
};
let input_file_filenames = match input_file {
Some("-") => {
let stdin = std::io::stdin();
let lines: Vec<String> = stdin
.lock()
.lines()
.map(|l| l.expect("failed to read stdin"))
.collect();
flow_common::files::canonicalize_filenames(&cwd, &handle_imaginary, &lines)
}
Some(input_file) => {
let content = std::fs::read_to_string(input_file).expect("failed to read input file");
let lines: Vec<String> = content.lines().map(|l| l.to_string()).collect();
let file_dir = Path::new(input_file)
.parent()
.map(|p| p.to_string_lossy().to_string())
.unwrap_or_else(|| cwd.clone());
flow_common::files::canonicalize_filenames(&file_dir, &handle_imaginary, &lines)
}
None => vec![],
};
let cli_filenames = match filenames {
Some(filenames) => {
let names: Vec<String> = filenames.to_vec();
flow_common::files::canonicalize_filenames(&cwd, &handle_imaginary, &names)
}
None => vec![],
};
let mut result = cli_filenames;
result.extend(input_file_filenames);View on GitHub (pinned to f88ac94bcf)
Solutions
- Verify the path and permissions before running: `test -r list.txt && flow ... --input-file list.txt`
- Re-encode the file to UTF-8: `iconv -f UTF-16 -t UTF-8 list.txt > list.utf8.txt`, or in PowerShell use `Out-File -Encoding utf8`
- Use absolute paths for --input-file in cron/CI so cwd changes cannot break resolution
Example fix
# before (PowerShell wrote UTF-16 with BOM) flow check-contents --input-file files.txt # after iconv -f UTF-16 -t UTF-8 files.txt > files.utf8.txt flow check-contents --input-file files.utf8.txt
Defensive patterns
Strategy: validation
Validate before calling
// Validate existence, readability, and UTF-8 before passing --input-file:
let p = std::path::Path::new(list);
let bytes = std::fs::read(p).unwrap_or_else(|e| {
eprintln!("cannot read {p:?}: {e}");
std::process::exit(1);
});
if std::str::from_utf8(&bytes).is_err() {
eprintln!("{p:?} is not UTF-8 (PowerShell `>` writes UTF-16)");
std::process::exit(1);
} Try / catch
let content = match std::fs::read_to_string(input_file) {
Ok(c) => c,
Err(e) => flow_common_exit::exit(FlowExitStatus::InputError,
Some(&format!("cannot read input file {input_file:?}: {e}"))),
}; Prevention
- Always `test -r <list>` in scripts before invoking with --input-file
- Generate lists as UTF-8 (PowerShell: Out-File -Encoding utf8; never bare `>`)
- Use absolute paths for --input-file in cron/CI to survive cwd changes
When it happens
Trigger: A typo'd or stale --input-file path (list generated in a previous CI step that was cleaned); permission-restricted file; a list saved as UTF-16 with BOM — common when generated by PowerShell `>` redirection — which read_to_string rejects as invalid UTF-8.
Common situations: PowerShell/Windows-generated file lists (UTF-16LE); cron jobs using relative paths from a different cwd; artifacts deleted between pipeline stages; files with exotic encodings.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- failed to get current directory
- failed to read stdin
- failed to read stdin
- failed to write json errors
- failed to flush json errors
AI-assisted analysis of facebook/flow@f88ac94bcf (2026-08-20).
Data as JSON: /api/errors/79d2c02c7ca9d4fa.
Report an issue: GitHub.