apache/cassandra · error · IllegalArgumentException

Specify snapshot name or --all

Error message

Specify snapshot name or --all

What it means

`nodetool clearsnapshot` requires identifying what to clear: either a specific --snapshot name or the --all flag. Calling it with neither throws this IllegalArgumentException as argument validation before contacting the node.

Source

Thrown at src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java:64

    @Option(paramLabel = "snapshot_name", names = "-t", description = "Remove the snapshot with a given name")
    private String snapshotName = EMPTY;

    @Option(paramLabel = "clear_all_snapshots", names = "--all", description = "Removes all snapshots")
    private boolean clearAllSnapshots = false;

    @Option(paramLabel = "older_than", names = "--older-than", description = "Clear snapshots older than specified time period.")
    private String olderThan;

    @Option(paramLabel = "older_than_timestamp", names = "--older-than-timestamp",
            description = "Clear snapshots older than specified timestamp. It has to be a string in ISO format, for example '2022-12-03T10:15:30Z'")
    private String olderThanTimestamp;

    @Override
    public void execute(NodeProbe probe)
    {
        if (snapshotName.isEmpty() && !clearAllSnapshots)
            throw new IllegalArgumentException("Specify snapshot name or --all");

        if (!snapshotName.isEmpty() && clearAllSnapshots)
            throw new IllegalArgumentException("Specify only one of snapshot name or --all");

        if (olderThan != null && olderThanTimestamp != null)
            throw new IllegalArgumentException("Specify only one of --older-than or --older-than-timestamp");

        if (!snapshotName.isEmpty() && olderThan != null)
            throw new IllegalArgumentException("Specifying snapshot name together with --older-than flag is not allowed");

        if (!snapshotName.isEmpty() && olderThanTimestamp != null)
            throw new IllegalArgumentException("Specifying snapshot name together with --older-than-timestamp flag is not allowed");

        if (olderThanTimestamp != null)
            try
            {
                Instant.parse(olderThanTimestamp);
            }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Pass a snapshot name: `nodetool clearsnapshot --snapshot <name>`
  2. Use `nodetool clearsnapshot --all` to remove all snapshots (after confirming intent)
  3. List existing snapshots with `nodetool listsnapshots` first to pick the right name

Example fix

// before
nodetool clearsnapshot
// after
nodetool clearsnapshot --all
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$SNAP" ] && [ -z "$ALL" ]; then echo "need --snapshot or --all"; exit 1; fi

Try / catch

try { clearSnapshot(); }
catch (IllegalArgumentException e) { System.err.println(e.getMessage()); }

Prevention

When it happens

Trigger: Running bare `nodetool clearsnapshot` with no --snapshot/-n and no --all flag.

Common situations: Scripted snapshot cleanup that forgot the flag, users assuming default behavior clears snapshots, version upgrades where flag defaults changed.

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


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/450a9e0f0f5d56d3. Report an issue: GitHub.