-
Notifications
You must be signed in to change notification settings - Fork 58
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
refactor: common error interface for elcontracts chainReader #477
Open
maximopalopoli
wants to merge
36
commits into
Layr-Labs:dev
Choose a base branch
from
lambdaclass:feat/common-error-interface
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
08311e1
Create error generic struct
maximopalopoli 64d8d09
Use generic error in some functions
maximopalopoli 7156732
Check returned string in one test case
maximopalopoli f65a3ae
Fix output err assert in TestContractErrorCases
maximopalopoli 905b68f
Use error interface in DigestHash reader functions
maximopalopoli 6210794
Use error interface in rewards coord related functions
maximopalopoli e2c7e03
Use error interface in allocationManager related funcs
maximopalopoli 29302b9
Use error interface in slashing related functions
maximopalopoli f728fa9
Run make fmt
maximopalopoli e865d24
Use error interface in admin functions
maximopalopoli 0173da5
Fix error assert in TestGetRootIndexFromRootHash
maximopalopoli 650ee6d
Add error text assert when expecting errors at reader tests
maximopalopoli 6a561fa
Change errLegacyAVSsNotSupported to use the error interface
maximopalopoli 9770917
Return err interface if init fails and add testcase
maximopalopoli f9663e6
Use CommonErrorMissingContract to avoid hardcoded strings
maximopalopoli db33f93
Fix failing test
maximopalopoli 9be131a
Use function to create missing contract errors at reader
maximopalopoli f0a1f0f
Rename error creation function
maximopalopoli 0cd9f20
Use function to create binding errors at reader
maximopalopoli 2701a62
Turn type 2 binding errors into Binding errors
maximopalopoli c2b8004
Use function to create nested errors at reader
maximopalopoli 8af9063
Turn NewReaderFromConfig returned err into a Nested one
maximopalopoli f971034
Update chainio/clients/elcontracts/error.go
maximopalopoli 6978c58
Remove metadata attribute in custom Error struct
maximopalopoli 3839676
Add Unwrap method to get the underlying error
maximopalopoli 3a25ed8
Merge branch 'dev' into feat/common-error-interface
maximopalopoli c9c1e74
Merge branch 'dev' into feat/common-error-interface
maximopalopoli 6ce8886
Rename custom error builders and its occurrences
maximopalopoli b56b255
Use full syntax when creating errors
maximopalopoli 7e6a276
Rename contracts names at errors following the solidity casing
maximopalopoli 3fda647
Use ErrorContains instead of comparing long literals
maximopalopoli 1349083
Move MissingContractError creation function
maximopalopoli 15ed4db
Create and use OtherError msg wrapper
maximopalopoli 2f4befa
Create only once legacyAVSsNotSupportedErrorMsg string
maximopalopoli 0565335
Merge branch 'dev' into feat/common-error-interface
maximopalopoli c4d5c23
Fix failing test
maximopalopoli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package elcontracts | ||
|
||
import "fmt" | ||
|
||
type Error struct { | ||
code int | ||
message string | ||
description string | ||
cause error | ||
} | ||
|
||
func (e Error) Error() string { | ||
if e.cause != nil { | ||
return fmt.Sprintf("%s(%d) - %s: %s", e.message, e.code, e.description, e.cause.Error()) | ||
} | ||
return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description) | ||
} | ||
|
||
func (e Error) Unwrap() error { | ||
return e.cause | ||
} | ||
|
||
func BindingError(bindingName string, errorCause error) Error { | ||
errDescription := fmt.Sprintf("Error happened while calling %s", bindingName) | ||
return Error{ | ||
code: 0, | ||
message: "Binding error", | ||
description: errDescription, | ||
cause: errorCause, | ||
} | ||
} | ||
|
||
func MissingContractError(contractName string) Error { | ||
errDescription := fmt.Sprintf("%s contract not provided", contractName) | ||
return Error{ | ||
code: 1, | ||
message: "Missing needed contract", | ||
description: errDescription, | ||
cause: nil, | ||
} | ||
} | ||
|
||
func NestedError(functionName string, errorCause error) Error { | ||
errDescription := fmt.Sprintf("Error happened while calling %s", functionName) | ||
return Error{ | ||
code: 2, | ||
message: "Nested error", | ||
description: errDescription, | ||
cause: errorCause, | ||
} | ||
} | ||
|
||
func OtherError(errDescription string, errorCause error) Error { | ||
return Error{ | ||
code: 3, | ||
message: "Other error", | ||
description: errDescription, | ||
cause: errorCause, | ||
} | ||
} | ||
|
||
func CommonErrorMissingContract(contractName string) string { | ||
return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about creating a type of "enum" for the errors codes? Maybe it would be more expressive?
I think that we can do something like this:
Do you think this is a good option? If not, we can use the current implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought about leaving a comment or something in the code that clarifies what type of error each ID is equivalent to, but I would prefer not to do so until I clearly define what error each one is equivalent to (it could change)