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

  1. Read the stderr message in the exception to see the exact ycqlsh error
  2. Validate CQL statements before adding them as init scripts
  3. Ensure getKeyspace() names an existing keyspace or create it before running statements
  4. 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

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


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)