{"record":{"id":"5df481138555b950","repo":"hashicorp/nomad","slug":"command-did-not-include-data","errorCode":null,"errorMessage":"command did not include data","messagePattern":"command did not include data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"helper/raftutil/state.go","lineNumber":165,"sourceCode":"\tIgnoreUnknownTypeFlag bool        `json:\",omitempty\"`\n\tBody                  interface{} `json:\",omitempty\"`\n}\n\nfunc decode(e *raft.Log) (*logMessage, error) {\n\tm := &logMessage{\n\t\tLogType: logTypes[e.Type],\n\t\tTerm:    e.Term,\n\t\tIndex:   e.Index,\n\t}\n\n\tif m.LogType == \"\" {\n\t\tm.LogType = fmt.Sprintf(\"%d\", e.Type)\n\t}\n\n\tvar data []byte\n\tif e.Type == raft.LogCommand {\n\t\tif len(e.Data) == 0 {\n\t\t\treturn nil, fmt.Errorf(\"command did not include data\")\n\t\t}\n\n\t\tmsgType := structs.MessageType(e.Data[0])\n\n\t\tm.CommandType = commandName(msgType & ^structs.IgnoreUnknownTypeFlag)\n\t\tm.IgnoreUnknownTypeFlag = (msgType & structs.IgnoreUnknownTypeFlag) != 0\n\n\t\tdata = e.Data[1:]\n\t} else {\n\t\tdata = e.Data\n\t}\n\n\tif len(data) != 0 {\n\t\tdecoder := codec.NewDecoder(bytes.NewReader(data), structs.MsgpackHandle)\n\n\t\tvar v interface{}\n\t\tvar err error\n\t\tif m.CommandType == commandName(structs.JobBatchDeregisterRequestType) {","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/helper/raftutil/state.go#L147-L183","documentation":"decode() parses a single raft log entry into a logMessage. When the entry type is raft.LogCommand, the payload must start with at least one byte (the message type) followed by the msgpack-encoded body. This error means the entry was marked as a command log but its Data field is empty, so there is no command type byte to inspect.","triggerScenarios":"LogEntries is called on a raft store (raft.db or wal/) and one of the entries read back has Type == raft.LogCommand with len(e.Data) == 0 — i.e. a zero-length command log was persisted in the raft log store.","commonSituations":"Corrupted or truncated raft.db / WAL files after disk-full events, crashes mid-write, or improper copy/restore of the data directory; manually edited or partially recovered raft stores being inspected with the raftutil inspection tooling.","solutions":["Identify the affected log index from the accompanying 'failed to decode log entry at index %d' warning in LogEntries and treat that entry's data as unrecoverable.","Restore the server's data directory from a verified backup or a healthy snapshot (nomad snapshot inspect/save) instead of trusting the corrupted raft log.","Run a raft store integrity check (e.g. open raft.db with bbolt in read-only, or verify the WAL segment checksums) to confirm corruption extent.","If the cluster is still quorate, remove the corrupted server from the cluster, wipe its data dir, and rejoin so raft is rebuilt from the leader.","Redeploy the tooling against a snapshot archive rather than raw raft logs when only state inspection is needed."],"exampleFix":"// before: tool aborts listing entries when it hits an empty LogCommand\nentries, warnings, err := raftutil.LogEntries(dataDir)\n// after: drain warnings and skip corrupt entries instead of failing the whole run\nentries, warnings, err := raftutil.LogEntries(dataDir)\nif err != nil { return err }\ngo func() {\n    for w := range warnings {\n        log.Printf(\"skipping bad raft entry: %v\", w)\n    }\n}()","handlingStrategy":"validation","validationCode":"// before trusting a LogCommand entry from LogEntries\nentries, warnings, err := raftutil.LogEntries(dataDir)\nif err != nil { return err }\nfor w := range warnings {\n    if strings.Contains(w.Error(), \"command did not include data\") {\n        log.Printf(\"corrupt empty command entry: %v\", w)\n    }\n}","typeGuard":null,"tryCatchPattern":"// Go: treat the warning channel as the error surface\nfor w := range warnings {\n    if strings.Contains(w.Error(), \"command did not include data\") {\n        // skip entry / mark store suspect\n        continue\n    }\n}","preventionTips":["Never copy or restore a raft data directory while the agent is running — stop Nomad first.","After any disk-full or crash event, validate the store before relying on its contents.","Keep the data dir on reliable storage with working fsync semantics.","Restore from verified snapshots rather than hand-edited raft files."],"tags":["raft","corruption","data-loss","storage"],"backgroundTag":"raft-log-corruption","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"}