OtterMind/Chat2DB · error · IllegalStateException
Existing routine definition does not contain routine name
Error message
Existing routine definition does not contain routine name
What it means
Thrown by qualifyCreateRoutineDdl when the DDL captured via SHOW CREATE does not begin with a recognisable 'PROCEDURE|FUNCTION <name>' token matching the regex (?is)\b(routineType)\s+(name). It is an IllegalStateException indicating the captured definition is in an unexpected format, so the code cannot safely qualify the unqualified routine name.
Source
Thrown at chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlRoutineManager.java:275
String showCreateRoutine(Connection connection, RoutineMigrationPlan migrationPlan) {
return DefaultSQLExecutor.getInstance().execute(
connection,
"SHOW CREATE " + migrationPlan.routineType() + " " + migrationPlan.qualifiedName(),
resultSet -> {
if (!resultSet.next()) {
return null;
}
return resultSet.getString("Create " + toTitleCase(migrationPlan.routineType()));
});
}
private String qualifyCreateRoutineDdl(String ddl, RoutineMigrationPlan migrationPlan) {
Pattern routineNamePattern = Pattern.compile(
"(?is)\\b" + migrationPlan.routineType()
+ "\\s+(`(?:``|[^`])+`|[A-Za-z0-9_$]+)(?:\\s*\\.\\s*(`(?:``|[^`])+`|[A-Za-z0-9_$]+))?");
Matcher matcher = routineNamePattern.matcher(ddl);
if (!matcher.find()) {
throw new IllegalStateException("Existing routine definition does not contain routine name");
}
if (matcher.group(2) != null) {
return ddl;
}
return ddl.substring(0, matcher.start(1)) + migrationPlan.qualifiedName() + ddl.substring(matcher.end(1));
}
private String rootMessage(Throwable throwable) {
Throwable current = throwable;
while (current.getCause() != null) {
current = current.getCause();
}
return StringUtils.defaultIfBlank(current.getMessage(), current.getClass().getSimpleName());
}
private String toTitleCase(String routineType) {
String normalized = StringUtils.trimToEmpty(routineType).toLowerCase(Locale.ROOT);
if (StringUtils.isBlank(normalized)) {View on GitHub (pinned to 5ee1e990e7)
Solutions
- Capture the raw SHOW CREATE output for the failing routine and compare it against the expected pattern to find the deviation.
- If using a MySQL fork (MariaDB/Percona), verify it is a supported dialect for routine migration.
- Drop and recreate the routine manually so the stored DDL matches the canonical format, then retry.
- Upgrade to a MySQL version whose SHOW CREATE output is canonical, or adjust the caller to provide the DDL directly instead of relying on capture.
Example fix
// before
ExecuteResponse r = routineManager.executeMigration(connection, operation);
// after
try {
ExecuteResponse r = routineManager.executeMigration(connection, operation);
if (Boolean.FALSE.equals(r.getSuccess())) {
log.warn("Migration failed: {}", r.getMessage());
}
} catch (IllegalStateException e) {
log.error("Captured DDL for {} unparseable: {}", operation.getRoutineName(), e.getMessage());
throw e;
} Defensive patterns
Strategy: try-catch
Try / catch
try {
routineManager.executeMigration(connection, operation);
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().contains("does not contain routine name")) {
log.error("SHOW CREATE output for {} is unparseable; capture and inspect it manually",
operation.getRoutineName());
}
throw e;
} Prevention
- Inspect the raw SHOW CREATE output when this fires to find the format deviation.
- Confirm the server is a supported MySQL dialect for routine migration.
- Recreate routines whose stored DDL is non-canonical before migrating.
- Do not assume SHOW CREATE output is identical across MySQL forks.
When it happens
Trigger: Migration of a routine whose SHOW CREATE output does not start with the expected keyword/name shape: non-standard MySQL forks (MariaDB, Percona) with altered output, a localized/comment-prefixed DDL, a DEFINER-heavy preamble that shifts the match, or a server bug producing malformed DDL.
Common situations: Running routine migration against MariaDB or a managed MySQL (RDS/Aurora) whose SHOW CREATE output differs slightly; migrating routines created by an older MySQL version whose DDL format changed; DEFINER/SQL SECURITY clauses causing the regex anchored at the keyword to miss.
Related errors
- Existing routine definition is empty
- routine.operation.ddlRequired
- routine.operation.parameterLoadFailed
- routine.operation.typeUnsupported
- routine.operation.nameRequired
AI-assisted analysis of OtterMind/Chat2DB@5ee1e990e7 (2026-08-14).
Data as JSON: /api/errors/c5709b62a254df88.
Report an issue: GitHub.