{"record":{"id":"9a1cf28658569d48","repo":"hashicorp/nomad","slug":"failed-to-open-wal-logs-v","errorCode":null,"errorMessage":"failed to open WAL logs: %v","messagePattern":"failed to open WAL logs: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/state.go","lineNumber":83,"sourceCode":"\t}\n\n\tfirstIdx, err = s.FirstIndex()\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch first index: %v\", err)\n\t}\n\n\tlastIdx, err = s.LastIndex()\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch last index: %v\", err)\n\t}\n\n\treturn s, firstIdx, lastIdx, nil\n}\n\nfunc raftStateInfoWAL(p string) (store RaftStore, firstIdx uint64, lastIdx uint64, err error) {\n\ts, err := raftwal.Open(p)\n\tif err != nil {\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to open WAL logs: %v\", err)\n\t}\n\n\tfirstIdx, err = s.FirstIndex()\n\tif err != nil {\n\t\ts.Close()\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch first index: %v\", err)\n\t}\n\n\tlastIdx, err = s.LastIndex()\n\tif err != nil {\n\t\ts.Close()\n\t\treturn nil, 0, 0, fmt.Errorf(\"failed to fetch last index: %v\", err)\n\t}\n\n\treturn s, firstIdx, lastIdx, nil\n}\n\n// LogEntries reads the raft logs found in the data directory found at","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/state.go#L65-L101","documentation":"raftStateInfoWAL handles the case where path p is a directory containing a Raft WAL (write-ahead log). This error wraps a failure of raftwal.Open on that directory — the WAL could not be opened at all: missing/corrupt segment files, wrong directory contents, or I/O errors. The store is not yet open so no cleanup is needed before returning.","triggerScenarios":"raftwal.Open(p) failing when p is a directory: empty or nonexistent WAL segment files, corrupt segment naming/content, a directory that is a BoltDB state dir misdetected as WAL, or permission/I-O errors opening segment files.","commonSituations":"Inspecting a WAL-enabled node's directory where segments were partially written before a crash, pointing at an unrelated directory that happens to be a dir (so it is routed to the WAL path), or running without read permission on the WAL segment files.","solutions":["Verify the directory actually contains Raft WAL segments (correct file naming) and not another store layout.","Fix directory/file permissions so the segment files are readable.","Check the embedded error for specific segment corruption; restore WAL/state from a snapshot if segments are damaged.","Take a consistent copy of the WAL directory while the agent is stopped and inspect that copy.","If the node actually uses BoltDB state, pass the raft.db file path so raftStateInfoBoltDB is used instead."],"exampleFix":"// before\nstore, _, _, err := raftutil.RaftStateInfo(\"/var/lib/consul/raft\") // dir without WAL segments\n\n// after\np := \"/var/lib/consul/raft/raft.db\" // BoltDB state: pass the file, not the dir\nstore, _, _, err := raftutil.RaftStateInfo(p)","handlingStrategy":"validation","validationCode":"func validateWALDir(p string) error {\n    fi, err := os.Stat(p)\n    if err != nil {\n        return err\n    }\n    if !fi.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", p)\n    }\n    entries, err := os.ReadDir(p)\n    if err != nil {\n        return err\n    }\n    if len(entries) == 0 {\n        return fmt.Errorf(\"%s contains no WAL segments\", p)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"store, _, _, err := raftutil.RaftStateInfo(walDir)\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to open WAL logs\") {\n        log.Printf(\"WAL unreadable or wrong directory: %v\", err)\n    }\n}","preventionTips":["Confirm the directory really holds Raft WAL segments; pass raft.db instead for BoltDB state dirs.","Check read permissions on the directory and all segment files.","Inspect copies taken while the agent is stopped, not live WAL.","Verify segment file presence and naming before calling the library."],"tags":["raft","wal","corruption","go"],"backgroundTag":"raft-wal-open-failed","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"}