nodejs/node · error
failed to open input file [%s]: %s\n
Error message
failed to open input file [%s]: %s\n
What it means
`OpenInputFile` failed to `fopen` the given path in read-binary mode. The message prints the path (via `PrintablePath`, which substitutes "con" for NULL) and the errno string from `strerror(errno)`. This is a standard POSIX file-open failure.
Source
Thrown at deps/brotli/c/tools/brotli.c:788
" -Z, --best use best compression level (11) (default)\n"
"Simple options could be coalesced, i.e. '-9kf' is equivalent to '-9 -k -f'.\n"
"With no FILE, or when FILE is -, read standard input.\n"
"All arguments after '--' are treated as files.\n");
}
static const char* PrintablePath(const char* path) {
return path ? path : "con";
}
static BROTLI_BOOL OpenInputFile(const char* input_path, FILE** f) {
*f = NULL;
if (!input_path) {
*f = fdopen(MAKE_BINARY(STDIN_FILENO), "rb");
return BROTLI_TRUE;
}
*f = fopen(input_path, "rb");
if (!*f) {
fprintf(stderr, "failed to open input file [%s]: %s\n",
PrintablePath(input_path), strerror(errno));
return BROTLI_FALSE;
}
return BROTLI_TRUE;
}
static BROTLI_BOOL OpenOutputFile(const char* output_path, FILE** f,
BROTLI_BOOL force) {
int fd;
*f = NULL;
if (!output_path) {
*f = fdopen(MAKE_BINARY(STDOUT_FILENO), "wb");
return BROTLI_TRUE;
}
fd = open(output_path, O_CREAT | (force ? 0 : O_EXCL) | O_WRONLY | O_TRUNC,
S_IRUSR | S_IWUSR);
if (fd < 0) {
fprintf(stderr, "failed to open output file [%s]: %s\n",View on GitHub (pinned to 1b2de5e052)
Solutions
- Verify the file exists and is readable: `ls -l <path>`.
- Check the working directory if using a relative path.
- Fix permissions with `chmod` or run as the appropriate user.
- For stdin, omit the input path or use `-` instead of a filename.
Example fix
// before brotli ./data/input.bin // after brotli /abs/path/data/input.bin
Defensive patterns
Strategy: validation
Validate before calling
#include <unistd.h>
#include <stdbool.h>
bool input_file_readable(const char *path) {
if (!path) return true; // stdin is always attempted
return access(path, R_OK) == 0;
}
// Before calling brotli:
// if (!input_file_readable(path)) { handle_error(path); } Prevention
- Resolve all input paths to absolute paths before passing to brotli.
- Check `access(path, R_OK)` before invoking to fail early with a clear message.
- Verify file existence in the same working directory brotli will run in.
When it happens
Trigger: The input file does not exist (ENOENT), the caller lacks read permission (EACCES), a path component is not a directory (ENOTDIR), the file name is too long (ENAMETOOLONG), or too many files are open (EMFILE).
Common situations: Relative path resolved from an unexpected working directory; glob or find command returned a stale name; file on an NFS mount that is stale or unmounted; permissions changed between listing and reading.
Related errors
- failed to open output file [%s]: %s\n
- failed to open dictionary file [%s]: %s\n
- could not get size of dictionary file [%s]
- Error %s writing to the output path "%s"
- setting access bits failed for [%s]: %s\n
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/fda68168bbf026ef.
Report an issue: GitHub.