Most implementations[1][2] of raft StableStore interface; when you do a get for a key and the value returned happens to be a nil []byte, then they return an error.
Since we are using StableStore interface to persist (ballots and state), we need to check if the state exists(ie do a get). But instead of throwing an error if state is nil []byte, we need to 'catch' it and set it to nil.
state, err := a.acceptorStore.Get(key)
if err != nil && err.Error() == "not found" {
state, err = nil, nil
}
if err != nil {
return acceptorState{}, errors.Wrap(err, fmt.Sprintf("unable to get state for key:%v from acceptor:%v", key, a.ID))
}
it looks hideous and should be replaced with something better.
ref: