From 69c6c1b6bbc167652eef92ac3d4db0e50ce82c9d Mon Sep 17 00:00:00 2001 From: Aaron Buchwald Date: Thu, 30 Nov 2023 19:54:07 -0500 Subject: [PATCH 1/2] chains/atomic: add formatteed error to dup ops error --- chains/atomic/state.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/chains/atomic/state.go b/chains/atomic/state.go index cd7a3f2a0faa..538af2f44f50 100644 --- a/chains/atomic/state.go +++ b/chains/atomic/state.go @@ -6,6 +6,7 @@ package atomic import ( "bytes" "errors" + "fmt" "github.com/ava-labs/avalanchego/database" "github.com/ava-labs/avalanchego/database/linkeddb" @@ -86,7 +87,7 @@ func (s *state) SetValue(e *Element) error { } // This key was written twice, which is invalid - return errDuplicatedOperation + return fmt.Errorf("%w: setting value (Key=%x, Value=%x)", errDuplicatedOperation, e.Key, e.Value) } if err != database.ErrNotFound { // An unexpected error occurred, so we should propagate that error @@ -160,7 +161,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: removing (Key=%x)", errDuplicatedOperation, key) } // Remove [key] from the indexDB for each trait that has indexed this key. From 92bc283d37cbf18475d7c9bdd63628db6d9365e9 Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 1 Dec 2023 12:52:15 -0500 Subject: [PATCH 2/2] nit --- chains/atomic/state.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chains/atomic/state.go b/chains/atomic/state.go index 538af2f44f50..aee269915ea9 100644 --- a/chains/atomic/state.go +++ b/chains/atomic/state.go @@ -17,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. @@ -87,7 +90,7 @@ func (s *state) SetValue(e *Element) error { } // This key was written twice, which is invalid - return fmt.Errorf("%w: setting value (Key=%x, Value=%x)", errDuplicatedOperation, e.Key, e.Value) + 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 @@ -161,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 fmt.Errorf("%w: removing (Key=%x)", errDuplicatedOperation, key) + return fmt.Errorf("%w: Key=0x%x", errDuplicateRemove, key) } // Remove [key] from the indexDB for each trait that has indexed this key.