prestodb/presto · error · RuntimeException

Error reading from file %s: %s

Error message

Error reading from file %s: %s

What it means

When the CLI reads the query from --file, an IOException while reading the file is rethrown as a RuntimeException with the file path and the IO error message. It indicates the file couldn't be read, not that the SQL is invalid.

Source

Thrown at presto-cli/src/main/java/com/facebook/presto/cli/Console.java:109

        }

        initializeLogging(clientOptions.logLevelsFile);

        String query = clientOptions.execute;
        if (hasQuery) {
            query += ";";
        }

        if (isFromFile) {
            if (hasQuery) {
                throw new RuntimeException("both --execute and --file specified");
            }
            try {
                query = Files.asCharSource(new File(clientOptions.file), UTF_8).read();
                hasQuery = true;
            }
            catch (IOException e) {
                throw new RuntimeException(format("Error reading from file %s: %s", clientOptions.file, e.getMessage()));
            }
        }

        // abort any running query if the CLI is terminated
        AtomicBoolean exiting = new AtomicBoolean();
        ThreadInterruptor interruptor = new ThreadInterruptor();
        CountDownLatch exited = new CountDownLatch(1);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            exiting.set(true);
            interruptor.interrupt();
            awaitUninterruptibly(exited, EXIT_DELAY.toMillis(), MILLISECONDS);
        }));

        try (QueryRunner queryRunner = new QueryRunner(
                session,
                clientOptions.debug,
                clientOptions.runtime,
                Optional.ofNullable(clientOptions.socksProxy),

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the path in --file exists and is readable (ls -l; test -r)
  2. Run the CLI as a user with permission to read the file
  3. Check filesystem/mount health if the path is on network storage

Example fix

// before
presto --file /opt/scripts/missing.sql
// after
presto --file $(pwd)/queries/q.sql   # verify with: test -r queries/q.sql
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight file check
FILE="$1"
if [ ! -r "$FILE" ]; then echo "Cannot read $FILE" >&2; exit 1; fi

Try / catch

try { runCli("--file", path); } catch (RuntimeException e) { if (e.getMessage().startsWith("Error reading from file")) { /* surface path + cause to user */ } else throw e; }

Prevention

When it happens

Trigger: Files.asCharSource(new File(clientOptions.file), UTF_8).read() throws IOException — missing file, no read permission, or an I/O failure.

Common situations: Typo in --file path; file deleted between scheduling and execution; running the CLI as a user without read permission; reading from a dead mount/NFS path.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/882e3aab923c2e90. Report an issue: GitHub.