apache/hadoop · error · IllegalArgumentException
<snapshotDir> is missing.
Error message
<snapshotDir> is missing.
What it means
CreateSnapshot.processOptions (SnapshotCommands.java:67) throws IllegalArgumentException('<snapshotDir> is missing.') when the command receives zero arguments. 'hdfs dfs -createSnapshot' requires at least the snapshot directory (an HDFS snapshottable directory); the snapshot name is the optional second argument.
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java:67
*/
public static class CreateSnapshot extends FsCommand {
public static final String NAME = CREATE_SNAPSHOT;
public static final String USAGE = "<snapshotDir> [<snapshotName>]";
public static final String DESCRIPTION = "Create a snapshot on a directory";
private String snapshotName = null;
@Override
protected void processPath(PathData item) throws IOException {
if (!item.stat.isDirectory()) {
throw new PathIsNotDirectoryException(item.toString());
}
}
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
if (args.size() == 0) {
throw new IllegalArgumentException("<snapshotDir> is missing.");
}
if (args.size() > 2) {
throw new IllegalArgumentException("Too many arguments.");
}
if (args.size() == 2) {
snapshotName = args.removeLast();
}
}
@Override
protected void processArguments(LinkedList<PathData> items)
throws IOException {
super.processArguments(items);
if (numErrors != 0) { // check for error collecting paths
return;
}
assert(items.size() == 1);
PathData sroot = items.getFirst();View on GitHub (pinned to 2add963021)
Solutions
- Supply the snapshot directory: 'hadoop fs -createSnapshot /hdfs/dir' (auto-generates a timestamped name) or 'hadoop fs -createSnapshot /hdfs/dir mysnap'
- Guard scripts: ': "${SNAPDIR:?SNAPDIR must be set}"' before invoking
- Ensure the directory is snapshottable ('hdfs dfsadmin -allowSnapshot <dir>') once the argument is supplied
Example fix
# before hadoop fs -createSnapshot # createSnapshot: <snapshotDir> is missing. # after hadoop fs -createSnapshot /data/important mysnap-2026-08-22
Defensive patterns
Strategy: validation
Validate before calling
# shell: fail fast on unset vars
: "${SNAPDIR:?SNAPDIR must be set}"
hadoop fs -createSnapshot "$SNAPDIR" "$SNAPNAME" Try / catch
catch (IllegalArgumentException e) when '<snapshotDir> is missing' -> require and validate the directory argument before re-invoking
Prevention
- Quote and default-check all snapshot script variables
- Remember the arg order: directory first, optional name second
- Allow snapshots on the dir first (dfsadmin -allowSnapshot)
When it happens
Trigger: 'hadoop fs -createSnapshot' or 'hdfs dfs -createSnapshot' with no positional arguments (flags would already have failed parsing; this is the empty-args case). Scripts invoking createSnapshot with an unquoted/empty $DIR variable also reduce to zero args.
Common situations: Automation where the directory variable is unset or empty ('hadoop fs -createSnapshot "$SNAPDIR"' with SNAPDIR empty); operators testing the command without arguments; copy-paste from docs that show the optional name and omit the required dir placeholder meaning.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Too many arguments.
- Invalid read parameters: buf.length=%d, off=%d, len=%d
- Move destination must be different from source for %s.
- offset: %s is out of range [%s, %s]
- Invalid start or len parameter
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/1e8b3ba4543b7417.
Report an issue: GitHub.