Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more descriptive formatted error #2403

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions chains/atomic/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package atomic
import (
"bytes"
"errors"
"fmt"

"github.com/ava-labs/avalanchego/database"
"github.com/ava-labs/avalanchego/database/linkeddb"
Expand All @@ -16,7 +17,10 @@ import (
"github.com/ava-labs/avalanchego/utils/set"
)

var errDuplicatedOperation = errors.New("duplicated operation on provided value")
var (
errDuplicatePut = errors.New("duplicate put")
errDuplicateRemove = errors.New("duplicate remove")
)

type dbElement struct {
// Present indicates the value was removed before existing.
Expand Down Expand Up @@ -86,7 +90,7 @@ func (s *state) SetValue(e *Element) error {
}

// This key was written twice, which is invalid
return errDuplicatedOperation
return fmt.Errorf("%w: Key=0x%x Value=0x%x", errDuplicatePut, e.Key, e.Value)
}
if err != database.ErrNotFound {
// An unexpected error occurred, so we should propagate that error
Expand Down Expand Up @@ -160,7 +164,7 @@ func (s *state) RemoveValue(key []byte) error {

// Don't allow the removal of something that was already removed.
if !value.Present {
return errDuplicatedOperation
return fmt.Errorf("%w: Key=0x%x", errDuplicateRemove, key)
}

// Remove [key] from the indexDB for each trait that has indexed this key.
Expand Down
Loading