testcontainers/testcontainers-java · error · RuntimeException
${result.getStderr()}
Error message
${result.getStderr()} What it means
YugabyteDBYCQLDelegate.execute() runs ycqlsh statements inside the container and throws a RuntimeException containing the process stderr when the ycqlsh exit code is non-zero. This surfaces CQL statement failures from the in-container shell to the test JVM.
Solutions
- Read the stderr message in the exception to see the exact ycqlsh error
- Validate CQL statements before adding them as init scripts
- Ensure getKeyspace() names an existing keyspace or create it before running statements
- Check the exception's cause chain — it is rethrown as UncategorizedScriptException
Defensive patterns
Strategy: validation
Validate before calling
// validate CQL before init
if (!cql.trim().endsWith(";")) throw new IllegalArgumentException("CQL statement must end with ;"); Try / catch
try { container.withInitScript("init.cql").start(); } catch (RuntimeException e) { log.error("ycqlsh failed: {}", e.getMessage()); throw e; } Prevention
- Test init CQL against a local ycqlsh before adding to container config
- Ensure the keyspace exists before statements referencing it
- Check stderr in the exception message first — it contains the ycqlsh error
When it happens
Trigger: Executing CQL init statements via the yugabytedb container's ycqlsh delegate where ycqlsh returns a non-zero exit code (bad CQL syntax, missing keyspace, connection failure inside the container).
Common situations: Invalid keyspace name in container config; CQL script with syntax errors; keyspace not yet created when init scripts run; container not fully up.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- ${e.getMessage()}
- Error while executing init script
- Script execution failed
- Error while executing init script
- Script statement failed at line lineNumber in script…
AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12).
Data as JSON: /api/errors/1c1399e4526c91af.
Report an issue: GitHub.
Appendix: source
Thrown at modules/yugabytedb/src/main/java/org/testcontainers/containers/delegate/YugabyteDBYCQLDelegate.java:60
.findFirst()
.get()
.getValue()
.getIpAddress();
try {
ExecResult result = container.execInContainer(
BIN_PATH,
containerInterfaceIP,
"-u",
container.getUsername(),
"-p",
container.getPassword(),
"-k",
container.getKeyspace(),
"-e",
StringUtils.join(statements, ";")
);
if (result.getExitCode() != 0) {
throw new RuntimeException(result.getStderr());
}
} catch (Exception e) {
log.debug(e.getMessage(), e);
throw new UncategorizedScriptException(e.getMessage(), e);
}
}
}
View on GitHub (pinned to 8e549514e3)