{"record":{"id":"1f622100598edc40","repo":"apache/cassandra","slug":"specify-only-one-of-snapshot-name-or-all","errorCode":null,"errorMessage":"Specify only one of snapshot name or --all","messagePattern":"Specify only one of snapshot name or --all","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java","lineNumber":67,"sourceCode":"\n    @Option(paramLabel = \"clear_all_snapshots\", names = \"--all\", description = \"Removes all snapshots\")\n    private boolean clearAllSnapshots = false;\n\n    @Option(paramLabel = \"older_than\", names = \"--older-than\", description = \"Clear snapshots older than specified time period.\")\n    private String olderThan;\n\n    @Option(paramLabel = \"older_than_timestamp\", names = \"--older-than-timestamp\",\n            description = \"Clear snapshots older than specified timestamp. It has to be a string in ISO format, for example '2022-12-03T10:15:30Z'\")\n    private String olderThanTimestamp;\n\n    @Override\n    public void execute(NodeProbe probe)\n    {\n        if (snapshotName.isEmpty() && !clearAllSnapshots)\n            throw new IllegalArgumentException(\"Specify snapshot name or --all\");\n\n        if (!snapshotName.isEmpty() && clearAllSnapshots)\n            throw new IllegalArgumentException(\"Specify only one of snapshot name or --all\");\n\n        if (olderThan != null && olderThanTimestamp != null)\n            throw new IllegalArgumentException(\"Specify only one of --older-than or --older-than-timestamp\");\n\n        if (!snapshotName.isEmpty() && olderThan != null)\n            throw new IllegalArgumentException(\"Specifying snapshot name together with --older-than flag is not allowed\");\n\n        if (!snapshotName.isEmpty() && olderThanTimestamp != null)\n            throw new IllegalArgumentException(\"Specifying snapshot name together with --older-than-timestamp flag is not allowed\");\n\n        if (olderThanTimestamp != null)\n            try\n            {\n                Instant.parse(olderThanTimestamp);\n            }\n            catch (DateTimeParseException ex)\n            {\n                throw new IllegalArgumentException(\"Parameter --older-than-timestamp has to be a valid instant in ISO format.\");","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java#L49-L85","documentation":"`nodetool clearsnapshot` treats a named snapshot and the --all flag as mutually exclusive: --all already implies deleting every snapshot, so a name alongside it is ambiguous. Supplying both throws this IllegalArgumentException.","triggerScenarios":"Running `nodetool clearsnapshot --snapshot my_snap --all`.","commonSituations":"Scripts accumulating flags over time, users wanting 'this snapshot and all others' without realizing --all subsumes the name.","solutions":["Use only --all to delete every snapshot","Use only --snapshot <name> (repeatable per snapshot name) to delete specific ones","If the goal is selective cleanup, run clearsnapshot once per snapshot name instead of adding --all"],"exampleFix":"// before\nnodetool clearsnapshot --snapshot snap1 --all\n// after\nnodetool clearsnapshot --snapshot snap1","handlingStrategy":"validation","validationCode":"if snapName && allFlag: raise SystemExit(\"use --snapshot OR --all, not both\")","typeGuard":null,"tryCatchPattern":"try { clearSnapshot(); }\ncatch (IllegalArgumentException e) { /* fix flags */ }","preventionTips":["Choose one deletion mode per invocation","Review script flag accumulation","Prefer --all only after explicit confirmation"],"tags":["nodetool","cli","snapshots","validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}