{"record":{"id":"d23400c00cf55fbd","repo":"hashicorp/nomad","slug":"failed-to-open-snapshot-dir-v","errorCode":null,"errorMessage":"failed to open snapshot dir: %v","messagePattern":"failed to open snapshot dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/fsm.go","lineNumber":62,"sourceCode":"\nfunc NewFSM(p string) (*FSMHelper, error) {\n\t// Auto-detect the backend: look for wal/ directory first, then raft.db.\n\tstorePath, err := FindRaftStore(p)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to find raft store in %v: %v\", p, err)\n\t}\n\n\tstore, firstIdx, lastIdx, err := RaftStateInfo(storePath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open raft store %v: %v\", storePath, err)\n\t}\n\n\tlogger := hclog.L()\n\n\tsnaps, err := raft.NewFileSnapshotStoreWithLogger(p, 1000, logger)\n\tif err != nil {\n\t\tstore.Close()\n\t\treturn nil, fmt.Errorf(\"failed to open snapshot dir: %v\", err)\n\t}\n\n\tfsm, err := dummyFSM(logger)\n\tif err != nil {\n\t\tstore.Close()\n\t\treturn nil, err\n\t}\n\n\treturn &FSMHelper{\n\t\tpath:   p,\n\t\tlogger: logger,\n\t\tstore:  store,\n\t\tfsm:    fsm,\n\t\tsnaps:  snaps,\n\n\t\tlogFirstIdx: firstIdx,\n\t\tlogLastIdx:  lastIdx,\n\t\tnextIdx:     uint64(1),","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/fsm.go#L44-L80","documentation":"NewFSM wraps the error from raft.NewFileSnapshotStoreWithLogger when the snapshots directory under the data path cannot be created or opened. The raft library is closed first to release the state store. Commonly a permissions or path problem.","triggerScenarios":"Calling NewFSM when the snapshots/ directory cannot be created (read-only filesystem, permission denied, path is a file not a directory) or existing snapshot files are unreadable/corrupt.","commonSituations":"Running the tool as a non-root user against a root-owned data dir; mounting the data dir read-only; disk full preventing snapshot store creation.","solutions":["Check permissions on the data dir and its snapshots/ subdirectory (needs read/write)","Ensure the filesystem is writable and has free space","Verify the data path is a directory, not a regular file"],"exampleFix":"// before\nfsm, err := raftutil.NewFSM(dataDir)\n// after\nsnapDir := filepath.Join(dataDir, \"snapshots\")\nif err := os.MkdirAll(snapDir, 0o700); err != nil {\n    return fmt.Errorf(\"cannot prepare snapshot dir %s: %w\", snapDir, err)\n}\nfsm, err := raftutil.NewFSM(dataDir)","handlingStrategy":"validation","validationCode":"snapDir := filepath.Join(dataDir, \"snapshots\")\nif err := os.MkdirAll(snapDir, 0o700); err != nil {\n    return fmt.Errorf(\"snapshot dir not creatable/writable: %w\", err)\n}\nif err := checkFreeSpace(dataDir, 64*1024*1024); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":"if err := raftutil.NewFSM(dataDir); err != nil {\n    if strings.Contains(err.Error(), \"failed to open snapshot dir\") {\n        return fmt.Errorf(\"check permissions/writability of %s/snapshots: %w\", dataDir, err)\n    }\n    return err\n}","preventionTips":["Run tooling as the same user that owns the Nomad data dir","Avoid read-only mounts for data directories","Ensure sufficient disk space before raft operations","Pre-create and permission the snapshots/ directory"],"tags":["raft","filesystem","snapshot","permissions","go"],"backgroundTag":"snapshot-dir-unavailable","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}