{"record":{"id":"3934a78a2d94e1ff","repo":"quarkusio/quarkus","slug":"cannot-use-descending-and-ascending-order-at-the-s","errorCode":null,"errorMessage":"Cannot use descending and ascending order at the same time","messagePattern":"Cannot use descending and ascending order at the same time","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java","lineNumber":523,"sourceCode":"            list.add(\"LANGUAGE\");\n            list.add(lang);\n        }\n        if (expander != null) {\n            list.add(\"EXPANDER\");\n            list.add(expander);\n        }\n        if (scorer != null) {\n            list.add(\"SCORER\");\n            list.add(scorer);\n        }\n\n        if (explainScore) {\n            list.add(\"EXPLAINSCORE\");\n        }\n\n        if (asc != null || desc != null) {\n            if (asc != null && desc != null) {\n                throw new IllegalArgumentException(\"Cannot use descending and ascending order at the same time\");\n            }\n            list.add(\"SORTBY\");\n            if (asc != null) {\n                list.add(asc);\n                list.add(\"ASC\");\n            }\n            if (desc != null) {\n                list.add(desc);\n                list.add(\"DESC\");\n            }\n        }\n\n        if (offset != -1) {\n            list.add(\"LIMIT\");\n            list.add(Integer.toString(offset));\n            list.add(Integer.toString(count));\n        }\n","sourceCodeStart":505,"sourceCodeEnd":541,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java#L505-L541","documentation":"A FT.SEARCH SORTBY clause can only specify one sort direction. QueryArgs.toArgs() throws IllegalArgumentException when both ascending(...) and descending(...) were set on the same QueryArgs, since SORTBY <field> ASC|DESC accepts a single direction.","triggerScenarios":"Calling queryArgs.ascending(\"field\") and descending(\"field\") (on the same or different fields) on one QueryArgs instance before ft().search(), typically from conditional building where both branches executed.","commonSituations":"Conditional sort logic (if sortAsc ... else sortDesc) written so both setters run; reusing a QueryArgs instance across requests and mutating its direction; wanting multi-field sort and assuming asc+desc calls accumulate instead of conflict.","solutions":["Set only one of ascending() or descending() per QueryArgs","Use if/else so exactly one direction is applied","Create a fresh QueryArgs per request rather than reusing a mutated instance"],"exampleFix":"// before\nQueryArgs args = new QueryArgs();\nif (asc) args.ascending(\"ts\");\nif (!asc) args.descending(\"ts\"); // both set when asc flag logic is buggy\n// after\nQueryArgs args = asc ? new QueryArgs().ascending(\"ts\") : new QueryArgs().descending(\"ts\");","handlingStrategy":"validation","validationCode":"if (sortAsc != null && sortDesc != null) throw new IllegalStateException(\"Specify at most one sort direction in QueryArgs\");\nQueryArgs args = new QueryArgs();\nif (sortAsc != null) args.ascending(sortAsc); else if (sortDesc != null) args.descending(sortDesc);","typeGuard":"boolean validSort(String asc, String desc) {\n    return asc == null || desc == null;\n}","tryCatchPattern":"try {\n    ft.search(query, args);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"descending and ascending\")) {\n        throw new IllegalStateException(\"QueryArgs must not set both ascending() and descending()\", e);\n    }\n    throw e;\n}","preventionTips":["Set exactly one of ascending() or descending() per QueryArgs","Use if/else for direction selection, never two consecutive ifs","Use a fresh QueryArgs per search request instead of mutating shared ones"],"tags":["redis","redisearch","illegal-argument","client-side-validation","mutually-exclusive-args"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}