{"record":{"id":"0692b82df8845076","repo":"prestodb/presto","slug":"both-execute-and-file-specified","errorCode":null,"errorMessage":"both --execute and --file specified","messagePattern":"both --execute and --file specified","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-cli/src/main/java/com/facebook/presto/cli/Console.java","lineNumber":102,"sourceCode":"    {\n        ClientSession session = clientOptions.toClientSession();\n        boolean hasQuery = !isNullOrEmpty(clientOptions.execute);\n        boolean isFromFile = !isNullOrEmpty(clientOptions.file);\n\n        if (!hasQuery && !isFromFile) {\n            AnsiConsole.systemInstall();\n        }\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);","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-cli/src/main/java/com/facebook/presto/cli/Console.java#L84-L120","documentation":"The Presto CLI allows supplying a query either via --execute or via --file, but not both. Console.run concatenates --execute values and, if --file was also given, throws to prevent ambiguity about which query to run.","triggerScenarios":"Running presto with both --execute \"<sql>\" and --file <path> on the command line.","commonSituations":"Wrapping scripts that append --execute to a command template that already passes --file; copy-pasted CLI invocations combining both flags.","solutions":["Use only one of --execute or --file","Move the inline SQL into the file (or vice versa) and pass a single source","If flags come from a wrapper script, conditionally add --execute only when no --file is present"],"exampleFix":"// before\npresto --file queries/q.sql --execute \"SELECT 1\"\n// after\npresto --file queries/q.sql","handlingStrategy":"validation","validationCode":"// shell guard before invoking the CLI\nif [ -n \"$PRESTO_EXECUTE\" ] && [ -n \"$PRESTO_FILE\" ]; then\n  echo \"Use only one of --execute or --file\" >&2; exit 1;\nfi","typeGuard":null,"tryCatchPattern":"try { runCli(args); } catch (RuntimeException e) { if (e.getMessage().contains(\"--execute and --file\")) { /* strip one flag and retry */ } else throw e; }","preventionTips":["Build CLI arguments from exactly one query source","Lint wrapper scripts for duplicated query flags","Prefer --file for multi-line SQL to avoid ad-hoc --execute additions"],"tags":["cli","argument-conflict","presto-cli"],"backgroundTag":"conflicting-cli-flags","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"}