{"record":{"id":"c04a5b8fc417fc99","repo":"apache/cassandra","slug":"error-can-not-sort-by-host-when-there-is-not-r","errorCode":null,"errorMessage":"Error: Can not sort by host when there is not -r/--resolve-ip flag used.","messagePattern":"Error: Can not sort by host when there is not -r/--resolve-ip flag used\\.","errorType":"validation","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/Status.java","lineNumber":154,"sourceCode":"        if (hostIDMap.size() < nodesOfTokens)\n            isTokenPerNode = false;\n\n        if (sortBy == null)\n        {\n            if (isTokenPerNode)\n                sortBy = SortBy.token;\n            else\n                sortBy = SortBy.id;\n        }\n        else if (!isTokenPerNode && sortBy == SortBy.token)\n        {\n            errOut.printf(\"%nError: Can not sort by token when there is not token per node.%n\");\n            throw new IllegalArgumentException(\"Error: Can not sort by token when there is not token per node.\");\n        }\n        else if (!resolveIp && sortBy == SortBy.host)\n        {\n            errOut.printf(\"%nError: Can not sort by host when there is not -r/--resolve-ip flag used.%n\");\n            throw new IllegalArgumentException(\"Error: Can not sort by host when there is not -r/--resolve-ip flag used.\");\n        }\n\n        // Datacenters\n        for (Map.Entry<String, SetHostStatWithPort> dc : dcs.entrySet())\n        {\n            TableBuilder tableBuilder = sharedTable.next();\n            addNodesHeader(hasEffectiveOwns, tableBuilder);\n\n            ArrayListMultimap<InetAddressAndPort, HostStatWithPort> hostToTokens = ArrayListMultimap.create();\n            for (HostStatWithPort stat : dc.getValue())\n                hostToTokens.put(stat.endpointWithPort, stat);\n\n            Map<String, List<Object>> data = new HashMap<>();\n            for (InetAddressAndPort endpoint : hostToTokens.keySet())\n            {\n                Float owns = ownerships.get(endpoint.getHostAddressAndPort());\n                List<HostStatWithPort> tokens = hostToTokens.get(endpoint);\n","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/Status.java#L136-L172","documentation":"nodetool status can sort by host/IP only when the -r/--resolve-ip flag is used; without resolution the display shows DNS names or the internal format does not permit host-based ordering. Status.execute() prints the message to stderr and throws IllegalArgumentException.","triggerScenarios":"Running `nodetool status -s host` without -r, e.g. `nodetool status keyspace1 -s host`.","commonSituations":"Users asking for IP-sorted output while the node is displaying hostnames because -r was omitted.","solutions":["Add -r/--resolve-ip to the command together with -s host.","Choose a different sort key (id, address, load, own, token).","Update scripts to always pass -r when sorting by host."],"exampleFix":"// before\nnodetool status -s host\n// after\nnodetool status -r -s host","handlingStrategy":"validation","validationCode":"if (sortKey === 'host' && !args.includes('-r')) args.push('-r');","typeGuard":null,"tryCatchPattern":"try { runStatus(args); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Can not sort by host\")) { args.push('-r'); retry(); } else throw e; }","preventionTips":["Always pair -s host with -r in scripts","Prefer -s address if IP output is acceptable without resolution"],"tags":["nodetool","status","cli"],"backgroundTag":"missing-required-flag","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"}