{"record":{"id":"d15cd89d523ff5c1","repo":"OtterMind/Chat2DB","slug":"redis-command-execution-failed-sql-originalsql","errorCode":null,"errorMessage":"Redis command execution failed, sql=${originalSql}","messagePattern":"Redis command execution failed, sql=(.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-redis/src/main/java/ai/chat2db/plugin/redis/RedisScriptExecutor.java","lineNumber":142,"sourceCode":"            throw new BusinessException(RedisConstants.ERROR_SQL_ANALYSIS);\n        }\n        List<ExecuteResponse> result = new ArrayList<>();\n        for (String originalSql : sqlList) {\n            ExecuteResponse executeResult = executeCommand(originalSql);\n            result.add(executeResult);\n        }\n        return result;\n    }\n\n    private ExecuteResponse executeCommand(String originalSql) {\n        int pageNo = 1;\n        int pageSize = 0;\n        String sqlType = SqlTypeEnum.UNKNOWN.getCode();\n        ExecuteResponse executeResult = null;\n        try {\n            executeResult = doExecuteCommand(originalSql);\n        } catch (SQLException e) {\n            throw new IllegalStateException(\"Redis command execution failed, sql=\" + originalSql, e);\n        }\n        executeResult.setSqlType(sqlType);\n        executeResult.setOriginalSql(originalSql);\n        executeResult.setPageNo(pageNo);\n        pageSize = CollectionUtils.size(executeResult.getDataList());\n        executeResult.setPageSize(pageSize);\n        executeResult.setHasNextPage(Boolean.FALSE);\n        executeResult.setFuzzyTotal(String.valueOf(pageSize));\n        appendRowNumber(executeResult, pageNo, pageSize);\n        return executeResult;\n    }\n\n    private void appendRowNumber(ExecuteResponse executeResult, int pageNo, int pageSize) {\n        List<Header> headers = executeResult.getHeaderList();\n        Header rowNumberHeader = Header.builder()\n                .name(I18nUtils.getMessage(\"sqlResult.rowNumber\"))\n                .dataType(DataTypeEnum.CHAT2DB_ROW_NUMBER\n                        .getCode()).build();","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-redis/src/main/java/ai/chat2db/plugin/redis/RedisScriptExecutor.java#L124-L160","documentation":"Thrown by RedisScriptExecutor.executeCommand as an IllegalStateException wrapping a SQLException from doExecuteCommand. This occurs when the underlying Redis JDBC driver rejects the command during query execution (stmt.execute at line 222). The original SQL is included in the message for diagnosis. This is a wrapper that preserves the SQLException as the cause.","triggerScenarios":"Calling RedisScriptExecutor.execute or executeSelectTable where doExecuteCommand throws SQLException. This happens when stmt.execute() at line 222 fails — e.g., the Redis JDBC driver reports a syntax error, the key does not exist for a type-specific query, or the connection is broken.","commonSituations":"Invalid Redis command syntax; querying a key whose type does not match the expected script; connection dropped mid-execution; Redis JDBC driver version incompatibility.","solutions":["Catch IllegalStateException at the call site and surface the cause SQLException to the user","Validate the Redis command syntax before execution","Check that the key exists and its type matches the query before calling executeSelectTable"],"exampleFix":"// before\nList<ExecuteResponse> results = executor.execute(command);\n\n// after\ntry {\n    List<ExecuteResponse> results = executor.execute(command);\n} catch (IllegalStateException e) {\n    log.error(\"Redis command failed: {}\", e.getMessage(), e.getCause());\n    // surface user-facing error\n}","handlingStrategy":"try-catch","validationCode":"// No pre-validation can fully prevent runtime SQLExceptions from the Redis driver.\n// Ensure the key exists and its type matches before calling executeSelectTable:\nString keyType = executor.getKeyType(command.getTableName());\nif (keyType == null || \"none\".equalsIgnoreCase(keyType)) {\n    // key does not exist; skip execution\n}","typeGuard":null,"tryCatchPattern":"try {\n    List<ExecuteResponse> results = executor.execute(command);\n} catch (IllegalStateException e) {\n    log.error(\"Redis command failed: {}\", e.getMessage());\n    Throwable cause = e.getCause(); // original SQLException\n    // surface to user\n}","preventionTips":["Verify the Redis key exists and its type matches the expected query before execution","Test commands against a Redis CLI before scripting them","Handle connection lifecycle carefully — broken connections cause SQLExceptions"],"tags":["redis","jdbc","execution","runtime-exception"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}