{"record":{"id":"dfa20cc0f3fb33f7","repo":"apache/cassandra","slug":"argument-for-sort-must-be-one-of-s","errorCode":null,"errorMessage":"argument for sort must be one of: %s","messagePattern":"argument for sort must be one of: (.+?)","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/TableStats.java","lineNumber":96,"sourceCode":"            description = \"Show only the top K tables for the sort key (specify the number K of tables to be shown\")\n    private int top = 0;\n\n    @Option(paramLabel = \"sstable_location_check\",\n            names = { \"-l\", \"--sstable-location-check\" },\n            description = \"Check whether or not the SSTables are in the correct location.\")\n    private boolean locationCheck = false;\n\n    @Override\n    public void execute(NodeProbe probe)\n    {\n        if (!outputFormat.isEmpty() && !\"json\".equals(outputFormat) && !\"yaml\".equals(outputFormat))\n        {\n            throw new IllegalArgumentException(\"arguments for -F are json,yaml only.\");\n        }\n\n        if (!sortKey.isEmpty() && !Arrays.asList(StatsTableComparator.supportedSortKeys).contains(sortKey))\n        {\n            throw new IllegalArgumentException(String.format(\"argument for sort must be one of: %s\",\n                                               String.join(\", \", StatsTableComparator.supportedSortKeys)));\n        }\n\n        if (top > 0 && sortKey.isEmpty())\n        {\n            throw new IllegalArgumentException(\"cannot filter top K tables without specifying a sort key.\");\n        }\n\n        if (top < 0)\n        {\n            throw new IllegalArgumentException(\"argument for top must be a positive integer.\");\n        }\n\n        StatsHolder holder = new TableStatsHolder(probe, humanReadable, ignore, tableNames, sortKey, top, locationCheck);\n        // print out the keyspace and table statistics\n        StatsPrinter printer = TableStatsPrinter.from(outputFormat, !sortKey.isEmpty());\n        printer.print(holder, probe.output().out);\n    }","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/TableStats.java#L78-L114","documentation":"TableStats supports sorting output via a sort key, validated against StatsTableComparator.supportedSortKeys. Passing a key outside that allowlist throws IllegalArgumentException listing the valid keys. This prevents silent no-op sorts on misspelled column names.","triggerScenarios":"`nodetool tablestats -s <wrongKey>` where the key is not in supportedSortKeys (e.g. 'write_latency' instead of the exact supported name like 'write_latency_ms' or whatever the build's list contains).","commonSituations":"Guessing sort-key names instead of copying from the error message; scripts written against an older Cassandra version whose supported key list changed; mixing up space- vs underscore-separated names.","solutions":["Read the error message, which enumerates the valid keys, and use one of them verbatim.","Check StatsTableComparator.supportedSortKeys in the source for the exact names in your Cassandra version.","Upgrade/downgrade scripts to match the key names of the deployed Cassandra version."],"exampleFix":"// before\nnodetool tablestats -s write_latency --top 5\n// after\nnodetool tablestats -s write_latency_ms --top 5  // use a key from supportedSortKeys","handlingStrategy":"validation","validationCode":"// read valid keys from the error output once and hardcode the allowlist\njava.util.Set<String> valid = java.util.Set.of(\"write_latency_ms\", \"read_latency_ms\", \"sstables_per_read\", \"space_used_live\");\nif (!valid.contains(sortKey)) throw new IllegalArgumentException(\"bad sort key: \" + sortKey);","typeGuard":null,"tryCatchPattern":"try { runNodetool(\"tablestats\", \"-s\", key); }\ncatch (IllegalArgumentException e) { if (e.getMessage().contains(\"argument for sort\")) { /* parse valid keys from message and retry */ } else throw e; }","preventionTips":["Copy sort-key names from the error message or nodetool help output, never guess.","Pin scripts to a Cassandra version and re-validate keys on upgrade.","Prefer loading supportedSortKeys from the same version's JAR in tooling."],"tags":["nodetool","cli","sort-key"],"backgroundTag":"invalid-enum-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}