apache/cassandra · error · java.lang.IllegalArgumentException
Error: Can not sort by host when there is not…
Error message
Error: Can not sort by host when there is not -r/--resolve-ip flag used.
What it means
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.
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.
Example fix
// before nodetool status -s host // after nodetool status -r -s host
Defensive patterns
Strategy: validation
Validate before calling
if (sortKey === 'host' && !args.includes('-r')) args.push('-r'); Try / catch
try { runStatus(args); } catch (IllegalArgumentException e) { if (e.getMessage().contains("Can not sort by host")) { args.push('-r'); retry(); } else throw e; } Prevention
- Always pair -s host with -r in scripts
- Prefer -s address if IP output is acceptable without resolution
When it happens
Trigger: Running `nodetool status -s host` without -r, e.g. `nodetool status keyspace1 -s host`.
Common situations: Users asking for IP-sorted output while the node is displaying hostnames because -r was omitted.
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- argument for sort must be one of
- argument for top must be a positive integer.
- arguments for -F are json,yaml only.
- arguments for -F are json,yaml only.
- arguments for -F are json,yaml only.
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/c04a5b8fc417fc99.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/tools/nodetool/Status.java:154
if (hostIDMap.size() < nodesOfTokens)
isTokenPerNode = false;
if (sortBy == null)
{
if (isTokenPerNode)
sortBy = SortBy.token;
else
sortBy = SortBy.id;
}
else if (!isTokenPerNode && sortBy == SortBy.token)
{
errOut.printf("%nError: Can not sort by token when there is not token per node.%n");
throw new IllegalArgumentException("Error: Can not sort by token when there is not token per node.");
}
else if (!resolveIp && sortBy == SortBy.host)
{
errOut.printf("%nError: Can not sort by host when there is not -r/--resolve-ip flag used.%n");
throw new IllegalArgumentException("Error: Can not sort by host when there is not -r/--resolve-ip flag used.");
}
// Datacenters
for (Map.Entry<String, SetHostStatWithPort> dc : dcs.entrySet())
{
TableBuilder tableBuilder = sharedTable.next();
addNodesHeader(hasEffectiveOwns, tableBuilder);
ArrayListMultimap<InetAddressAndPort, HostStatWithPort> hostToTokens = ArrayListMultimap.create();
for (HostStatWithPort stat : dc.getValue())
hostToTokens.put(stat.endpointWithPort, stat);
Map<String, List<Object>> data = new HashMap<>();
for (InetAddressAndPort endpoint : hostToTokens.keySet())
{
Float owns = ownerships.get(endpoint.getHostAddressAndPort());
List<HostStatWithPort> tokens = hostToTokens.get(endpoint);
View on GitHub (pinned to 88fd0f6a0e)