{"record":{"id":"61f24f17f62ffbc8","repo":"testcontainers/testcontainers-java","slug":"error-while-executing-init-script-initscriptpath-61f24f","errorCode":null,"errorMessage":"Error while executing init script: {} + initScriptPath","messagePattern":"Error while executing init script: (.+?) \\+ initScriptPath","errorType":"exception","errorClass":"UncategorizedScriptException","httpStatus":null,"severity":"error","filePath":"modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java","lineNumber":114,"sourceCode":"    private void runInitScriptIfRequired() {\n        if (initScriptPath != null) {\n            try {\n                URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);\n                if (resource == null) {\n                    logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                    throw new ScriptLoadException(\n                        \"Could not load classpath init script: \" + initScriptPath + \". Resource not found.\"\n                    );\n                }\n                String cql = IOUtils.toString(resource, StandardCharsets.UTF_8);\n                DatabaseDelegate databaseDelegate = getDatabaseDelegate();\n                ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, cql);\n            } catch (IOException e) {\n                logger().warn(\"Could not load classpath init script: {}\", initScriptPath);\n                throw new ScriptLoadException(\"Could not load classpath init script: \" + initScriptPath, e);\n            } catch (ScriptException e) {\n                logger().error(\"Error while executing init script: {}\", initScriptPath, e);\n                throw new ScriptUtils.UncategorizedScriptException(\n                    \"Error while executing init script: \" + initScriptPath,\n                    e\n                );\n            }\n        }\n    }\n\n    /**\n     * Map (effectively replace) directory in Docker with the content of resourceLocation if resource location is not null\n     *\n     * Protected to allow for changing implementation by extending the class\n     *\n     * @param pathNameInContainer path in docker\n     * @param resourceLocation    relative classpath to resource\n     */\n    protected void optionallyMapResourceParameterAsVolume(String pathNameInContainer, String resourceLocation) {\n        Optional\n            .ofNullable(resourceLocation)","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/cassandra/src/main/java/org/testcontainers/containers/CassandraContainer.java#L96-L132","documentation":"When executing the init CQL script via ScriptUtils.executeDatabaseScript throws a ScriptException (a statement in the script failed to parse/execute), CassandraContainer logs 'Error while executing init script' and rethrows as ScriptUtils.UncategorizedScriptException with the script path. The container start aborts.","triggerScenarios":"container.start() with a valid, loadable init script whose CQL contains syntax errors, unsupported statements, or statements failing against the Cassandra node.","commonSituations":"CQL written for a different Cassandra version (e.g. system_schema vs system tables); invalid CREATE TABLE syntax; using directives unsupported by ScriptUtils (comment separators).","solutions":["Fix the CQL in the init script; test it manually with cqlsh against the same image version","Match the script to the container's Cassandra version (check keyspace/table names in system_schema)","Check the cause chain of UncategorizedScriptException for the exact failing statement and line"],"exampleFix":"// before (init.cql)\nCREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy'};\n// after\nCREATE KEYSPACE IF NOT EXISTS test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};","handlingStrategy":"validation","validationCode":"// Validate CQL locally before wiring the container:\n// run the script against a matching Cassandra version via cqlsh or a local node","typeGuard":null,"tryCatchPattern":"try { container.start(); } catch (UncategorizedScriptException e) { /* e.getCause() names the failing statement/line */ }","preventionTips":["Test init CQL manually with cqlsh on the same image version","Keep scripts version-compatible with the Cassandra tag used","Use IF NOT EXISTS in DDL statements"],"tags":["cassandra","testcontainers","cql","script-execution","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"}