{"record":{"id":"882e3aab923c2e90","repo":"prestodb/presto","slug":"error-reading-from-file-s-s","errorCode":null,"errorMessage":"Error reading from file %s: %s","messagePattern":"Error reading from file (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-cli/src/main/java/com/facebook/presto/cli/Console.java","lineNumber":109,"sourceCode":"        }\n\n        initializeLogging(clientOptions.logLevelsFile);\n\n        String query = clientOptions.execute;\n        if (hasQuery) {\n            query += \";\";\n        }\n\n        if (isFromFile) {\n            if (hasQuery) {\n                throw new RuntimeException(\"both --execute and --file specified\");\n            }\n            try {\n                query = Files.asCharSource(new File(clientOptions.file), UTF_8).read();\n                hasQuery = true;\n            }\n            catch (IOException e) {\n                throw new RuntimeException(format(\"Error reading from file %s: %s\", clientOptions.file, e.getMessage()));\n            }\n        }\n\n        // abort any running query if the CLI is terminated\n        AtomicBoolean exiting = new AtomicBoolean();\n        ThreadInterruptor interruptor = new ThreadInterruptor();\n        CountDownLatch exited = new CountDownLatch(1);\n        Runtime.getRuntime().addShutdownHook(new Thread(() -> {\n            exiting.set(true);\n            interruptor.interrupt();\n            awaitUninterruptibly(exited, EXIT_DELAY.toMillis(), MILLISECONDS);\n        }));\n\n        try (QueryRunner queryRunner = new QueryRunner(\n                session,\n                clientOptions.debug,\n                clientOptions.runtime,\n                Optional.ofNullable(clientOptions.socksProxy),","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-cli/src/main/java/com/facebook/presto/cli/Console.java#L91-L127","documentation":"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.","triggerScenarios":"Files.asCharSource(new File(clientOptions.file), UTF_8).read() throws IOException — missing file, no read permission, or an I/O failure.","commonSituations":"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.","solutions":["Verify the path in --file exists and is readable (ls -l; test -r)","Run the CLI as a user with permission to read the file","Check filesystem/mount health if the path is on network storage"],"exampleFix":"// before\npresto --file /opt/scripts/missing.sql\n// after\npresto --file $(pwd)/queries/q.sql   # verify with: test -r queries/q.sql","handlingStrategy":"validation","validationCode":"// pre-flight file check\nFILE=\"$1\"\nif [ ! -r \"$FILE\" ]; then echo \"Cannot read $FILE\" >&2; exit 1; fi","typeGuard":null,"tryCatchPattern":"try { runCli(\"--file\", path); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"Error reading from file\")) { /* surface path + cause to user */ } else throw e; }","preventionTips":["Use absolute paths for --file","Check readability of SQL files in CI before invoking the CLI","Avoid reading query files from network mounts in automated jobs"],"tags":["cli","io","file-not-found"],"backgroundTag":"file-read-failed","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}