{"record":{"id":"c19cd68c9f4efd68","repo":"nats-io/nats-server","slug":"could-not-create-snapshots-directory-v","errorCode":null,"errorMessage":"could not create snapshots directory - %v","messagePattern":"could not create snapshots directory - (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/raft.go","lineNumber":558,"sourceCode":"\t\t// the error upwards, otherwise we can complete recovery but have only\n\t\t// a partial view of the world.\n\t\tn.shutdown()\n\t\treturn nil, err\n\t}\n\n\t// We may have restored the peer state from the\n\t// snapshot above. If not, we restore peers from\n\t// the peer state file.\n\tif len(n.peers) == 0 {\n\t\tif err := restorePeerState(n); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\t// Make sure that the snapshots directory exists.\n\tif err := os.MkdirAll(filepath.Join(n.sd, snapshotsDir), defaultDirPerms); err != nil {\n\t\tn.shutdown()\n\t\treturn nil, fmt.Errorf(\"could not create snapshots directory - %v\", err)\n\t}\n\n\ttruncateAndErr := func(index uint64) {\n\t\tif err := n.wal.Truncate(index); err != nil {\n\t\t\tn.setWriteErr(err)\n\t\t}\n\t}\n\n\t// Retrieve the stream state from the WAL. If there are pending append\n\t// entries that were committed but not applied before we last shut down,\n\t// we will try to replay them and process them here.\n\tvar state StreamState\n\tn.wal.FastState(&state)\n\tn.bytes = state.Bytes\n\n\tif state.Msgs > 0 {\n\t\tn.debug(\"Replaying state of %d entries\", state.Msgs)\n","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/raft.go#L540-L576","documentation":"When creating the raft node, NATS ensures <store_dir>/snapshots exists using os.MkdirAll; failure triggers shutdown of the node and this error. It means the server could not create the snapshots directory (or a parent component) on disk.","triggerScenarios":"os.MkdirAll(filepath.Join(n.sd, snapshotsDir), defaultDirPerms) returns an error: parent path is a file, permission denied on parent, read-only mount, or disk full.","commonSituations":"JetStream store directory contains a file named 'snapshots', store path on a read-only container volume, or partially-migrated store directories with wrong ownership.","solutions":["Inspect the wrapped %v error for the exact os cause (EACCES/ENOSPC/ENOTDIR).","Remove any file occupying the snapshots path, or fix permissions/ownership of the store directory.","Remount the store volume writable or relocate store_dir to writable storage.","Ensure the server runs as a user with write access to the JetStream store root."],"exampleFix":"// before: a file blocks the dir\n# file /data/js/snapshots\n/data/js/snapshots: ASCII text\n// after\nrm /data/js/snapshots && mkdir -p /data/js/snapshots","handlingStrategy":"validation","validationCode":"snapDir := filepath.Join(storeDir, \"snapshots\")\nif info, err := os.Stat(snapDir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"%q is a file, blocking snapshots dir\", snapDir)\n}\nif err := os.MkdirAll(snapDir, 0750); err != nil {\n    return err\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create store_dir and store_dir/snapshots with correct ownership in provisioning.","Never store files named 'snapshots' inside the raft store directory.","Keep store volumes writable and monitor capacity."],"tags":["raft","filesystem","jetstream"],"backgroundTag":"mkdir-failed","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}