apache/cassandra · error · IllegalArgumentException
Number of commands to display has to be at least 1.
Error message
Number of commands to display has to be at least 1.
What it means
The History nodetool command has a `-n/--commands` option (default 1000) controlling how many recent nodetool commands to print. execute() validates it and throws IllegalArgumentException if the value is less than 1, since printing 'zero or negative' commands is meaningless.
Solutions
- Pass a positive integer, e.g. `nodetool history -n 50`
- Fix the script that computes the count so it clamps to at least 1
- Omit -n entirely to use the default of 1000
Example fix
// before nodetool history -n 0 // after nodetool history -n 1 # or omit -n for default 1000
Defensive patterns
Strategy: validation
Validate before calling
# clamp the command count before invoking if [ "$N" -lt 1 ]; then echo "-n must be >= 1"; exit 1; fi
Try / catch
try { runNodetool("history","-n",String.valueOf(n)); } catch (IllegalArgumentException e) { log("invalid -n: " + n, e); } Prevention
- Ensure script-computed counts are clamped to >= 1
- Use Math.max(1, n) when computing the limit in code
- Omit -n to accept the default of 1000
When it happens
Trigger: Running `nodetool history -n 0` or `nodetool history -n -5`, or passing an empty/0 value via a script variable.
Common situations: Scripts computing a limit that evaluates to 0 (e.g. subtracting counts); users trying to 'disable' history printing by passing 0; off-by-one when trimming output.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- argument for top must be a positive integer.
- arguments for -F are json,yaml only.
- Can not parse replication factor
- Keyspace [ ] does not exist.
- Parameter --older-than-timestamp has to be a valid instant…
AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10).
Data as JSON: /api/errors/ddab4d0ae4fd6626.
Report an issue: GitHub.
Appendix: source
Thrown at src/java/org/apache/cassandra/tools/nodetool/History.java:44
import org.apache.cassandra.tools.NodeTool;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
@Command(name = "history", description = "Print previously executed nodetool commands")
public class History extends AbstractCommand implements LocalCommand
{
@Option(paramLabel = "commands",
names = { "-n", "--num", "--number-of-commands" },
description = "Number of commands to print, defaults to 1000.")
public int commands = 1000;
@Override
protected void execute(NodeProbe probe)
{
if (commands < 1)
throw new IllegalArgumentException("Number of commands to display has to be at least 1.");
File historyFile = getHistoryFile();
validateHistoryFile(historyFile);
for (String line : commandsToPrint(historyFile))
output.out.println(line);
}
@Override
protected boolean shouldConnect() throws CommandLine.ExecutionException
{
return false;
}
File getHistoryFile()
{
return NodeTool.getHistoryFile();
}View on GitHub (pinned to 88fd0f6a0e)