{"record":{"id":"824431cfa19abf9f","repo":"testcontainers/testcontainers-java","slug":"script-execution-failed-s-d-s","errorCode":null,"errorMessage":"Script execution failed (%s:%d): %s","messagePattern":"Script execution failed \\((.+?):(.+?)\\): (.+?)","errorType":"exception","errorClass":"org.testcontainers.ext.ScriptUtils.ScriptStatementFailedException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/cassandra/CassandraDatabaseDelegate.java","lineNumber":76,"sourceCode":"            if (StringUtils.isBlank(statement)) {\n                executeArg = \"-f\";\n                executeArgValue = scriptPath;\n            }\n            cqlshCommand = ArrayUtils.addAll(cqlshCommand, executeArg, executeArgValue);\n\n            Container.ExecResult result =\n                this.container.execInContainer(ExecConfig.builder().command(cqlshCommand).build());\n            if (result.getExitCode() == 0) {\n                if (StringUtils.isBlank(statement)) {\n                    log.info(\"CQL script {} successfully executed\", scriptPath);\n                } else {\n                    log.info(\"CQL statement {} was applied\", statement);\n                }\n            } else {\n                if (!silentErrorLogs) {\n                    log.error(\"CQL script execution failed with error: \\n{}\", result.getStderr());\n                }\n                throw new ScriptStatementFailedException(statement, lineNumber, scriptPath);\n            }\n        } catch (IOException | InterruptedException e) {\n            throw new ScriptStatementFailedException(statement, lineNumber, scriptPath, e);\n        }\n    }\n\n    @Override\n    public void execute(\n        String statement,\n        String scriptPath,\n        int lineNumber,\n        boolean continueOnError,\n        boolean ignoreFailedDrops\n    ) {\n        this.execute(statement, scriptPath, lineNumber, continueOnError, ignoreFailedDrops, false);\n    }\n\n    @Override","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/cassandra/CassandraDatabaseDelegate.java#L58-L94","documentation":"CassandraDatabaseDelegate.execute runs a CQL statement/script inside the Cassandra container via ExecConfig and inspects the result. When the executed command reports a non-zero/failed outcome with stderr output (and error logs are not silenced), it throws ScriptStatementFailedException formatted as 'Script execution failed (%s:%d): %s' with the statement, line number, and script path.","triggerScenarios":"Calling container.executeCql(...) or the delegate's execute(String statement,...) with CQL that cqlsh/inline execution rejects; also thrown for any statement run through containerIsStarting/init flows whose exec result reports an error.","commonSituations":"Invalid CQL syntax; schema operations timing out on slow Cassandra startup (schema disagreement); referencing keyspaces/tables not yet created; running scripts during containerIsStarting before Cassandra is fully ready.","solutions":["Inspect the logged stderr ('CQL script execution failed with error') for the server-side reason","Fix the CQL statement; validate it manually via cqlsh in the same container version","If thrown during startup, wait for full readiness before executing CQL (use follow-up wait strategies / execute after containerIsStarted)","Retry schema statements if caused by transient schema agreement delays, or set a larger schema agreement timeout in Cassandra config"],"exampleFix":"// before\ncontainer.executeCql(\"ALTER TABLE keyspace.t ADD col int;\"); // t does not exist yet\n// after\ncontainer.executeCql(\"CREATE TABLE IF NOT EXISTS keyspace.t (id uuid PRIMARY KEY, col int);\");\ncontainer.executeCql(\"ALTER TABLE keyspace.t ADD col int;\");","handlingStrategy":"try-catch","validationCode":"// sanity-check CQL with a lightweight parser or dry-run against a scratch container before executing in tests","typeGuard":null,"tryCatchPattern":"try {\n    container.executeCql(statement);\n} catch (ScriptStatementFailedException e) {\n    log.error(\"CQL failed at line {}: {}\", e.getLineNumber(), statement, e);\n    throw new AssertionError(\"Fix CQL statement\", e);\n}","preventionTips":["Read the logged 'CQL script execution failed with error' stderr for the server reason","Validate scripts against the exact Cassandra version used by the container","Execute schema DDL only after the container is fully ready, not mid-startup"],"tags":["cassandra","cql","script-execution","exec"],"backgroundTag":"sql-query-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}