{"record":{"id":"c5709b62a254df88","repo":"OtterMind/Chat2DB","slug":"existing-routine-definition-does-not-contain-routi","errorCode":null,"errorMessage":"Existing routine definition does not contain routine name","messagePattern":"Existing routine definition does not contain routine name","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlRoutineManager.java","lineNumber":275,"sourceCode":"    String showCreateRoutine(Connection connection, RoutineMigrationPlan migrationPlan) {\n        return DefaultSQLExecutor.getInstance().execute(\n                connection,\n                \"SHOW CREATE \" + migrationPlan.routineType() + \" \" + migrationPlan.qualifiedName(),\n                resultSet -> {\n                    if (!resultSet.next()) {\n                        return null;\n                    }\n                    return resultSet.getString(\"Create \" + toTitleCase(migrationPlan.routineType()));\n                });\n    }\n\n    private String qualifyCreateRoutineDdl(String ddl, RoutineMigrationPlan migrationPlan) {\n        Pattern routineNamePattern = Pattern.compile(\n                \"(?is)\\\\b\" + migrationPlan.routineType()\n                        + \"\\\\s+(`(?:``|[^`])+`|[A-Za-z0-9_$]+)(?:\\\\s*\\\\.\\\\s*(`(?:``|[^`])+`|[A-Za-z0-9_$]+))?\");\n        Matcher matcher = routineNamePattern.matcher(ddl);\n        if (!matcher.find()) {\n            throw new IllegalStateException(\"Existing routine definition does not contain routine name\");\n        }\n        if (matcher.group(2) != null) {\n            return ddl;\n        }\n        return ddl.substring(0, matcher.start(1)) + migrationPlan.qualifiedName() + ddl.substring(matcher.end(1));\n    }\n\n    private String rootMessage(Throwable throwable) {\n        Throwable current = throwable;\n        while (current.getCause() != null) {\n            current = current.getCause();\n        }\n        return StringUtils.defaultIfBlank(current.getMessage(), current.getClass().getSimpleName());\n    }\n\n    private String toTitleCase(String routineType) {\n        String normalized = StringUtils.trimToEmpty(routineType).toLowerCase(Locale.ROOT);\n        if (StringUtils.isBlank(normalized)) {","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-mysql/src/main/java/ai/chat2db/plugin/mysql/MysqlRoutineManager.java#L257-L293","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nExecuteResponse r = routineManager.executeMigration(connection, operation);\n\n// after\ntry {\n    ExecuteResponse r = routineManager.executeMigration(connection, operation);\n    if (Boolean.FALSE.equals(r.getSuccess())) {\n        log.warn(\"Migration failed: {}\", r.getMessage());\n    }\n} catch (IllegalStateException e) {\n    log.error(\"Captured DDL for {} unparseable: {}\", operation.getRoutineName(), e.getMessage());\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    routineManager.executeMigration(connection, operation);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"does not contain routine name\")) {\n        log.error(\"SHOW CREATE output for {} is unparseable; capture and inspect it manually\",\n            operation.getRoutineName());\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["mysql","routine","migration","compatibility"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}