testcontainers/testcontainers-java · error · RuntimeException
Error while executing init script
Error message
Error while executing init script: ${scriptPath} What it means
When session.execute("sql", script) throws UnsupportedOperationException (e.g. the OrientDB session/driver refuses the SQL script execution mode), loadScript rethrows it as RuntimeException 'Error while executing init script: <path>' with the original as cause.
Solutions
- Check the cause (UnsupportedOperationException) and make the script statements valid OrientDB SQL
- Split the script into statements your OrientDB version supports, or use a JVM driver call per statement
- Update the OrientDB container image/version to one matching the script syntax
Example fix
// before // init.sql using unsupported gremlin syntax CREATE CLASS Foo EXTENDS V; GREMLIN-style commands... // after CREATE CLASS Foo EXTENDS V; CREATE PROPERTY Foo.name STRING;
Defensive patterns
Strategy: try-catch
Validate before calling
// pre-validate script contains only supported OrientDB SQL statements before handing it to withInitScript
Try / catch
try {
container.start();
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Error while executing init script")) {
log.error("Init script rejected by OrientDB: {}", scriptPath, e.getCause());
}
throw e;
} Prevention
- Test init scripts against the same OrientDB version as the container image
- Use only OrientDB SQL syntax in scripts (no Gremlin/other languages)
- Pin the container image version to match script compatibility
When it happens
Trigger: Executing an init script whose statements or execution mode aren't supported by the OrientDB session — e.g. non-SQL script content against the 'sql' language, or a driver/DB version that doesn't support script execution.
Common situations: Feeding scripts with Gremlin/OrientJS-only commands into the sql executor; using a script written for a newer OrientDB version; init scripts with syntax the embedded server version rejects.
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Could not load classpath init script
- Could not load classpath init script
- Could not load classpath init script
- 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/7c23f2c7183dfc73.
Report an issue: GitHub.
Appendix: source
Thrown at modules/orientdb/src/main/java/org/testcontainers/containers/OrientDBContainer.java:191
try {
URL resource = getClass().getClassLoader().getResource(path);
if (resource == null) {
LOGGER.warn("Could not load classpath init script: {}", scriptPath);
throw new RuntimeException(
"Could not load classpath init script: " + scriptPath + ". Resource not found."
);
}
String script = IOUtils.toString(resource, StandardCharsets.UTF_8);
session.execute("sql", script);
} catch (IOException e) {
LOGGER.warn("Could not load classpath init script: {}", scriptPath);
throw new RuntimeException("Could not load classpath init script: " + scriptPath, e);
} catch (UnsupportedOperationException e) {
LOGGER.error("Error while executing init script: {}", scriptPath, e);
throw new RuntimeException("Error while executing init script: " + scriptPath, e);
}
}
}
View on GitHub (pinned to 8e549514e3)