{"record":{"id":"1d2dc38ff85df25f","repo":"testcontainers/testcontainers-java","slug":"error-while-executing-init-script-initscriptpath","errorCode":null,"errorMessage":"Error while executing init script: ${initScriptPath}","messagePattern":"Error while executing init script: (.+?)","errorType":"exception","errorClass":"org.testcontainers.ext.ScriptUtils.UncategorizedScriptException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/cassandra/CassandraContainer.java","lineNumber":111,"sourceCode":"    private void runInitScriptIfRequired() {\n        if (this.initScriptPath != null) {\n            try {\n                final MountableFile originalInitScript = MountableFile.forClasspathResource(this.initScriptPath);\n                // The init script is executed as is by the cqlsh command, so copy it into the container. The name\n                // of the script is generic since it's not important to keep the original name.\n                copyFileToContainer(originalInitScript, DEFAULT_INIT_SCRIPT_FILENAME);\n                new CassandraDatabaseDelegate(this).execute(null, DEFAULT_INIT_SCRIPT_FILENAME, -1, false, false);\n            } catch (IllegalArgumentException e) {\n                // MountableFile.forClasspathResource will throw an IllegalArgumentException if the resource cannot\n                // be found.\n                logger().warn(\"Could not load classpath init script: {}\", this.initScriptPath);\n                throw new ScriptLoadException(\n                    \"Could not load classpath init script: \" + this.initScriptPath + \". Resource not found.\",\n                    e\n                );\n            } catch (ScriptUtils.ScriptStatementFailedException e) {\n                logger().error(\"Error while executing init script: {}\", this.initScriptPath, e);\n                throw new ScriptUtils.UncategorizedScriptException(\n                    \"Error while executing init script: \" + this.initScriptPath,\n                    e\n                );\n            }\n        }\n    }\n\n    /**\n     * Initialize Cassandra with the custom overridden Cassandra configuration\n     * <p>\n     * Be aware, that Docker effectively replaces all /etc/cassandra content with the content of config location, so if\n     * Cassandra.yaml in configLocation is absent or corrupted, then Cassandra just won't launch.\n     *\n     * @param configLocation relative classpath with the directory that contains cassandra.yaml and other configuration\n     *                       files\n     * @return The updated {@link CassandraContainer}.\n     */\n    public CassandraContainer withConfigurationOverride(String configLocation) {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/cassandra/CassandraContainer.java#L93-L129","documentation":"After Cassandra starts and the init script is loaded, runInitScriptIfRequired executes its statements via CassandraDatabaseDelegate. If a CQL statement in the script fails (ScriptUtils.ScriptStatementFailedException), the container wraps it in an UncategorizedScriptException with this message. Unlike error 76 the script was found — a statement inside it is invalid or failed at runtime.","triggerScenarios":"withInitScript(...) pointing to a loadable script whose CQL contains syntax errors, references a non-existent keyspace/table, violates constraints (duplicate CREATE, invalid type), or fails because the server rejected the statement.","commonSituations":"Scripts written for a different Cassandra version (unsupported syntax); statements depending on objects created earlier in the same script that failed silently or in wrong order; invalid CQL copied from cqlsh with cqlsh-only directives.","solutions":["Read the accompanying log/exception for the exact failing statement and Cassandra's error message","Validate the script by running it manually against the same Cassandra version (docker run + cqlsh)","Fix the offending CQL (syntax, ordering, existence checks like CREATE TABLE IF NOT EXISTS)","Align the script with the container's Cassandra version if it uses version-specific syntax"],"exampleFix":"// before (init.cql)\nCREATE TABLE users (id uuid PRIMARY KEY, name text);\nCREATE TABLE users (id uuid PRIMARY KEY, name text); -- duplicate -> fails\n// after\nCREATE TABLE IF NOT EXISTS users (id uuid PRIMARY KEY, name text);","handlingStrategy":"try-catch","validationCode":"// pre-validate the script offline with an embedded validator or run against a scratch Cassandra container before the test suite","typeGuard":null,"tryCatchPattern":"try {\n    container.start();\n} catch (UncategorizedScriptException e) {\n    Throwable root = getRootCause(e);\n    log.error(\"CQL in {} failed: {}\", container.getInitScript(), root.getMessage());\n    throw new AssertionError(\"Fix init script statement: \" + container.getInitScript(), e);\n}","preventionTips":["Run the init script manually via cqlsh against the same Cassandra image version before CI","Use IF NOT EXISTS / idempotent statements and correct statement ordering","Keep scripts free of cqlsh-only directives"],"tags":["cassandra","cql","init-script","script-execution"],"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"}