{"record":{"id":"762e1a3ef56eb832","repo":"OtterMind/Chat2DB","slug":"invalid-sql-server-index-column-sort-order-ascor","errorCode":null,"errorMessage":"Invalid SQL Server index column sort order: {ascOrDesc}","messagePattern":"Invalid SQL Server index column sort order: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"chat2db-community-server/chat2db-community-plugins/chat2db-community-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/enums/type/SqlServerIndexTypeEnum.java","lineNumber":113,"sourceCode":"        StringBuilder script = new StringBuilder();\n        script.append(\"(\");\n        for (TableIndexColumn column : tableIndex.getColumnList()) {\n            if (StringUtils.isNotBlank(column.getColumnName())) {\n                script.append(SqlServerIdentifierProcessor.INSTANCE.quoteIdentifierAlways(column.getColumnName()));\n                if (!StringUtils.isBlank(column.getAscOrDesc()) && !PRIMARY_KEY.equals(this)) {\n                    script.append(\" \").append(validateAscOrDesc(column.getAscOrDesc()));\n                }\n                script.append(\",\");\n            }\n        }\n        script.deleteCharAt(script.length() - 1);\n        script.append(\")\");\n        return script.toString();\n    }\n\n    private static String validateAscOrDesc(String ascOrDesc) {\n        if (!\"ASC\".equalsIgnoreCase(ascOrDesc) && !\"DESC\".equalsIgnoreCase(ascOrDesc)) {\n            throw new IllegalArgumentException(\"Invalid SQL Server index column sort order: \" + ascOrDesc);\n        }\n        return ascOrDesc;\n    }\n\n    private String buildIndexName(TableIndex tableIndex) {\n        return SqlServerIdentifierProcessor.INSTANCE.quoteIdentifierAlways(tableIndex.getName());\n    }\n\n    public String buildModifyIndex(TableIndex tableIndex) {\n        if (EditStatusEnum.DELETE.name().equals(tableIndex.getEditStatus())) {\n            return buildDropIndex(tableIndex);\n        }\n        if (EditStatusEnum.MODIFY.name().equals(tableIndex.getEditStatus())) {\n            return StringUtils.join(buildDropIndex(tableIndex), \"\\n\", buildIndexScript(tableIndex));\n        }\n        if (EditStatusEnum.ADD.name().equals(tableIndex.getEditStatus())) {\n            return StringUtils.join(buildIndexScript(tableIndex));\n        }","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/OtterMind/Chat2DB/blob/5ee1e990e73fbcae1969dc554be254fedb3ab888/chat2db-community-server/chat2db-community-plugins/chat2db-community-sqlserver/src/main/java/ai/chat2db/plugin/sqlserver/enums/type/SqlServerIndexTypeEnum.java#L95-L131","documentation":"Thrown by SqlServerIndexTypeEnum.validateAscOrDesc when an index column's sort order is neither ASC nor DESC (case-insensitive). The value is emitted verbatim into the index DDL, so only the two canonical directions are allowed.","triggerScenarios":"A TableIndexColumn with getAscOrDesc() set to a blank, null, or non-canonical value reaching validateAscOrDesc - e.g. '' , 'A', 'ASCENDING', or 'NULLS FIRST'. (The caller only invokes the validator when the value is non-blank.)","commonSituations":"Default/empty sort metadata passed as a non-empty placeholder; UI storing a label; cross-dialect data carrying 'NULLS FIRST' which SQL Server indexes do not support per-column.","solutions":["Set ascOrDesc to 'ASC' or 'DESC', or leave it null/blank so the caller skips the validator.","Normalize any third-party metadata to ASC/DESC before populating the index column.","Treat empty sort as 'no direction' rather than sending a placeholder token."],"exampleFix":"// before\ncol.setAscOrDesc(\"ASCENDING\");\n// -> Invalid SQL Server index column sort order\n\n// after\ncol.setAscOrDesc(\"ASC\");","handlingStrategy":"validation","validationCode":"if (StringUtils.isNotBlank(col.getAscOrDesc())\n        && !\"ASC\".equalsIgnoreCase(col.getAscOrDesc())\n        && !\"DESC\".equalsIgnoreCase(col.getAscOrDesc())) {\n    throw new IllegalArgumentException(\"Bad sort order: \" + col.getAscOrDesc());\n}","typeGuard":"static boolean isValidAscOrDesc(String v) {\n    return v == null || v.isBlank() || \"ASC\".equalsIgnoreCase(v) || \"DESC\".equalsIgnoreCase(v);\n}","tryCatchPattern":null,"preventionTips":["Use only ASC/DESC, or leave blank to omit direction.","Normalize imported metadata to ASC/DESC.","Do not send placeholder tokens."],"tags":["sqlserver","ddl","index","validation"],"backgroundTag":null,"analyzedSha":"5ee1e990e73fbcae1969dc554be254fedb3ab888","analyzedAt":"2026-08-14T07:05:03.077Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}