Skip to content

Commit

Permalink
[chains/atomic] Remove a nested if statement (#3135)
Browse files Browse the repository at this point in the history
Signed-off-by: Dhruba Basu <7675102+dhrubabasu@users.noreply.github.com>
  • Loading branch information
dhrubabasu committed Jun 20, 2024
1 parent 28b4790 commit f8fa3cf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions chains/atomic/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ func (s *state) SetValue(e *Element) error {
// current engine state.
func (s *state) RemoveValue(key []byte) error {
value, err := s.loadValue(key)
if err != nil {
if err != database.ErrNotFound {
// An unexpected error occurred, so we should propagate that error
return err
}

if err == database.ErrNotFound {
// The value doesn't exist, so we should optimistically delete it
dbElem := dbElement{Present: false}
valueBytes, err := Codec.Marshal(CodecVersion, &dbElem)
Expand All @@ -161,6 +156,9 @@ func (s *state) RemoveValue(key []byte) error {
}
return s.valueDB.Put(key, valueBytes)
}
if err != nil {
return err
}

// Don't allow the removal of something that was already removed.
if !value.Present {
Expand Down

0 comments on commit f8fa3cf

Please sign in to comment.