{"record":{"id":"1e8b3ba4543b7417","repo":"apache/hadoop","slug":"snapshotdir-is-missing","errorCode":null,"errorMessage":"<snapshotDir> is missing.","messagePattern":"<snapshotDir> is missing\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java","lineNumber":67,"sourceCode":"   */\n  public static class CreateSnapshot extends FsCommand {\n    public static final String NAME = CREATE_SNAPSHOT;\n    public static final String USAGE = \"<snapshotDir> [<snapshotName>]\";\n    public static final String DESCRIPTION = \"Create a snapshot on a directory\";\n\n    private String snapshotName = null;\n\n    @Override\n    protected void processPath(PathData item) throws IOException {\n      if (!item.stat.isDirectory()) {\n        throw new PathIsNotDirectoryException(item.toString());\n      }\n    }\n    \n    @Override\n    protected void processOptions(LinkedList<String> args) throws IOException {\n      if (args.size() == 0) {\n        throw new IllegalArgumentException(\"<snapshotDir> is missing.\");\n      } \n      if (args.size() > 2) {\n        throw new IllegalArgumentException(\"Too many arguments.\");\n      }\n      if (args.size() == 2) {\n        snapshotName = args.removeLast();\n      }\n    }\n\n    @Override\n    protected void processArguments(LinkedList<PathData> items)\n    throws IOException {\n      super.processArguments(items);\n      if (numErrors != 0) { // check for error collecting paths\n        return;\n      }\n      assert(items.size() == 1);\n      PathData sroot = items.getFirst();","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/SnapshotCommands.java#L49-L85","documentation":"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.","triggerScenarios":"'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.","commonSituations":"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.","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"],"exampleFix":"# before\nhadoop fs -createSnapshot\n# createSnapshot: <snapshotDir> is missing.\n\n# after\nhadoop fs -createSnapshot /data/important mysnap-2026-08-22","handlingStrategy":"validation","validationCode":"# shell: fail fast on unset vars\n: \"${SNAPDIR:?SNAPDIR must be set}\"\nhadoop fs -createSnapshot \"$SNAPDIR\" \"$SNAPNAME\"","typeGuard":null,"tryCatchPattern":"catch (IllegalArgumentException e) when '<snapshotDir> is missing' -> require and validate the directory argument before re-invoking","preventionTips":["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)"],"tags":["createsnapshot","missing-argument","argument-validation","snapshot","hadoop-shell"],"backgroundTag":"missing-required-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}