{"record":{"id":"4931a30d66a7680f","repo":"testcontainers/testcontainers-java","slug":"script-statement-failed-at-line-linenumber-in-script","errorCode":null,"errorMessage":"Script statement failed at line lineNumber in script scriptPath (statement: statement)","messagePattern":"Script statement failed at line lineNumber in script scriptPath \\(statement: statement\\)","errorType":"exception","errorClass":"ScriptStatementFailedException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/delegate/CassandraDatabaseDelegate.java","lineNumber":49,"sourceCode":"            log.error(\"Could not obtain cassandra connection\");\n            throw new ConnectionCreationException(\"Could not obtain cassandra connection\", 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        try {\n            ResultSet result = getConnection().execute(statement);\n            if (result.wasApplied()) {\n                log.debug(\"Statement {} was applied\", statement);\n            } else {\n                throw new ScriptStatementFailedException(statement, lineNumber, scriptPath);\n            }\n        } catch (DriverException e) {\n            throw new ScriptStatementFailedException(statement, lineNumber, scriptPath, e);\n        }\n    }\n\n    @Override\n    protected void closeConnectionQuietly(Session session) {\n        try {\n            session.getCluster().close();\n        } catch (Exception e) {\n            log.error(\"Could not close cassandra connection\", e);\n        }\n    }\n}\n","sourceCodeStart":31,"sourceCodeEnd":65,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/delegate/CassandraDatabaseDelegate.java#L31-L65","documentation":"CassandraDatabaseDelegate.execute runs a CQL statement and checks ResultSet.wasApplied(). If the statement did not apply (e.g. a conditional LWT or DDL that was rejected/rolled back), it throws ScriptStatementFailedException with statement, line number, and script path. This is the 'not applied' branch, without a driver-level exception.","triggerScenarios":"execute(statement, ...) where getConnection().execute(statement) returns a ResultSet with wasApplied()==false — typically a failed conditional (IF EXISTS / IF NOT EXISTS) statement or a rejected statement surfaced as not-applied.","commonSituations":"Init scripts using CREATE TABLE IF NOT EXISTS where the object already exists; lightweight transactions whose condition failed; re-running scripts against a reused container.","solutions":["Make statements idempotent or guard with IF NOT EXISTS and tolerate the not-applied result","Inspect the statement at the reported script line and run it manually via cqlsh to see why it was not applied","If state from a previous run conflicts, use a fresh container or drop the keyspace first"],"exampleFix":"// before (init.cql)\nCREATE TABLE test.users (id uuid PRIMARY KEY, name text);\n// after (safe on re-run)\nCREATE TABLE IF NOT EXISTS test.users (id uuid PRIMARY KEY, name text);","handlingStrategy":"validation","validationCode":"// Prefer statements that report applied=true; guard DDL with IF NOT EXISTS","typeGuard":null,"tryCatchPattern":"try { container.start(); } catch (ContainerLaunchException e) { /* ScriptStatementFailedException names statement, line, script */ }","preventionTips":["Write idempotent init scripts with IF NOT EXISTS","Start with a fresh container when re-running scripts","Test each statement's applied status via cqlsh"],"tags":["cassandra","testcontainers","cql","statement-failed","init-script"],"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"}