{"record":{"id":"686479ed5abb52fe","repo":"hashicorp/nomad","slug":"failed-to-stat-s-v","errorCode":null,"errorMessage":"failed to stat %s: %v","messagePattern":"failed to stat (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/state.go","lineNumber":41,"sourceCode":"var (\n\terrAlreadyOpen = errors.New(\"unable to open raft logs that are in use\")\n)\n\n// RaftStore is the interface returned by RaftStateInfo, satisfied by both\n// *raftboltdb.BoltStore and *raftwal.WAL.\ntype RaftStore interface {\n\traft.LogStore\n\traft.StableStore\n\tClose() error\n}\n\n// RaftStateInfo returns info about the raft state found at path p. The path\n// may point to a BoltDB file (raft.db) or a WAL directory. The returned\n// RaftStore must be closed by the caller.\nfunc RaftStateInfo(p string) (store RaftStore, firstIdx uint64, lastIdx uint64, err error) {\n\tinfo, statErr := os.Stat(p)\n\tif statErr != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to stat %s: %v\", p, statErr)\n\t}\n\n\tif info.IsDir() {\n\t\treturn raftStateInfoWAL(p)\n\t}\n\treturn raftStateInfoBoltDB(p)\n}\n\nfunc raftStateInfoBoltDB(p string) (store RaftStore, firstIdx uint64, lastIdx uint64, err error) {\n\topts := raftboltdb.Options{\n\t\tPath: p,\n\t\tBoltOptions: &bbolt.Options{\n\t\t\tReadOnly: true,\n\t\t\tTimeout:  1 * time.Second,\n\t\t},\n\t\tMsgpackUseNewTimeFormat: true,\n\t}\n\ts, err := raftboltdb.New(opts)","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/state.go#L23-L59","documentation":"RaftStateInfo inspects the Raft state at path p (a BoltDB raft.db file or a WAL directory) and first calls os.Stat on it. This error means the path itself could not be stat'd: it does not exist, a parent directory is missing, or permission is denied. Nothing about the store format is involved yet.","triggerScenarios":"os.Stat(p) failing with ENOENT, ENOTDIR, EACCES, or ELOOP when calling RaftStateInfo with a wrong or inaccessible path to raft.db or the WAL directory.","commonSituations":"Typo in the data dir path (e.g. pointing at the parent data dir instead of raft/), running the tool as a user without permissions on Consul's data dir, or inspecting a node whose raft.db was never created (cluster never bootstrapped).","solutions":["Verify the path exists: pass the full path to raft.db (e.g. /var/lib/consul/raft/raft.db) or the WAL directory, not the parent data dir.","Fix permissions: run as a user that can traverse every directory component (often root or the consul service account).","Confirm the node has actually run and created raft state; a fresh node has no raft.db.","Stat the path yourself first (os.Stat / ls -l) and print the OS error to confirm ENOENT vs EACCES."],"exampleFix":"// before\nstore, _, _, err := raftutil.RaftStateInfo(\"/var/lib/consul\") // wrong: parent dir\n\n// after\np := \"/var/lib/consul/raft/raft.db\"\nif _, err := os.Stat(p); err != nil {\n    log.Fatalf(\"raft state not accessible: %v\", err)\n}\nstore, _, _, err := raftutil.RaftStateInfo(p)","handlingStrategy":"validation","validationCode":"func mustExist(p string) error {\n    if _, err := os.Stat(p); err != nil {\n        return fmt.Errorf(\"raft state path %q not accessible: %w\", p, err)\n    }\n    return nil\n}\n// call before RaftStateInfo\nif err := mustExist(raftPath); err != nil {\n    log.Fatal(err)\n}","typeGuard":null,"tryCatchPattern":"store, _, _, err := raftutil.RaftStateInfo(p)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to stat\") {\n        log.Fatalf(\"path %q missing or unreadable: %v\", p, err)\n    }\n}","preventionTips":["Pass the exact raft.db path or WAL directory, not the parent data dir.","Run inspection as a user with traverse/read permission on all path components.","os.Stat the path and log the OS error (ENOENT vs EACCES) before calling the library.","Remember a never-bootstrapped node has no raft.db yet."],"tags":["raft","filesystem","path","go"],"backgroundTag":"no-such-file-or-directory","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"}