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

refactor: common error interface for elcontracts chainReader #477

Open
wants to merge 36 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
08311e1
Create error generic struct
maximopalopoli Jan 27, 2025
64d8d09
Use generic error in some functions
maximopalopoli Jan 27, 2025
7156732
Check returned string in one test case
maximopalopoli Jan 27, 2025
f65a3ae
Fix output err assert in TestContractErrorCases
maximopalopoli Jan 28, 2025
905b68f
Use error interface in DigestHash reader functions
maximopalopoli Jan 28, 2025
6210794
Use error interface in rewards coord related functions
maximopalopoli Jan 28, 2025
e2c7e03
Use error interface in allocationManager related funcs
maximopalopoli Jan 28, 2025
29302b9
Use error interface in slashing related functions
maximopalopoli Jan 28, 2025
f728fa9
Run make fmt
maximopalopoli Jan 28, 2025
e865d24
Use error interface in admin functions
maximopalopoli Jan 28, 2025
0173da5
Fix error assert in TestGetRootIndexFromRootHash
maximopalopoli Jan 28, 2025
650ee6d
Add error text assert when expecting errors at reader tests
maximopalopoli Jan 28, 2025
6a561fa
Change errLegacyAVSsNotSupported to use the error interface
maximopalopoli Jan 28, 2025
9770917
Return err interface if init fails and add testcase
maximopalopoli Jan 28, 2025
f9663e6
Use CommonErrorMissingContract to avoid hardcoded strings
maximopalopoli Jan 28, 2025
db33f93
Fix failing test
maximopalopoli Jan 28, 2025
9be131a
Use function to create missing contract errors at reader
maximopalopoli Jan 28, 2025
f0a1f0f
Rename error creation function
maximopalopoli Jan 28, 2025
0cd9f20
Use function to create binding errors at reader
maximopalopoli Jan 28, 2025
2701a62
Turn type 2 binding errors into Binding errors
maximopalopoli Jan 28, 2025
c2b8004
Use function to create nested errors at reader
maximopalopoli Jan 28, 2025
8af9063
Turn NewReaderFromConfig returned err into a Nested one
maximopalopoli Jan 28, 2025
f971034
Update chainio/clients/elcontracts/error.go
maximopalopoli Jan 29, 2025
6978c58
Remove metadata attribute in custom Error struct
maximopalopoli Jan 29, 2025
3839676
Add Unwrap method to get the underlying error
maximopalopoli Jan 29, 2025
3a25ed8
Merge branch 'dev' into feat/common-error-interface
maximopalopoli Jan 30, 2025
c9c1e74
Merge branch 'dev' into feat/common-error-interface
maximopalopoli Feb 3, 2025
6ce8886
Rename custom error builders and its occurrences
maximopalopoli Feb 3, 2025
b56b255
Use full syntax when creating errors
maximopalopoli Feb 5, 2025
7e6a276
Rename contracts names at errors following the solidity casing
maximopalopoli Feb 5, 2025
3fda647
Use ErrorContains instead of comparing long literals
maximopalopoli Feb 5, 2025
1349083
Move MissingContractError creation function
maximopalopoli Feb 5, 2025
15ed4db
Create and use OtherError msg wrapper
maximopalopoli Feb 5, 2025
2f4befa
Create only once legacyAVSsNotSupportedErrorMsg string
maximopalopoli Feb 5, 2025
0565335
Merge branch 'dev' into feat/common-error-interface
maximopalopoli Feb 5, 2025
c4d5c23
Fix failing test
maximopalopoli Feb 5, 2025
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
48 changes: 48 additions & 0 deletions chainio/clients/elcontracts/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package elcontracts

import "fmt"

type Error struct {
code int
Copy link
Contributor

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:

type ErrorCode int

const (
    ErrCodeBindingError ErrorCode = 0
    ErrCodeMissingContract
    ErrCodeNestedError
)

Do you think this is a good option? If not, we can use the current implementation.

Copy link
Contributor Author

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)

message string
description string
cause error
// metadata map[string]interface{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I left it just in case but could not find any use. Removed in 6978c58

}

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())
} else {
return fmt.Sprintf("%s(%d) - %s", e.message, e.code, e.description)
}
}
maximopalopoli marked this conversation as resolved.
Show resolved Hide resolved

func CreateErrorForMissingContract(contractName string) Error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename these functions to MissingContractError, BindingError, XError, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errDescription := fmt.Sprintf("%s contract not provided", contractName)
return Error{1, "Missing needed contract", errDescription, nil}
}

func CreateForBindingError(bindingName string, errorCause error) Error {
errDescription := fmt.Sprintf("Error happened while calling %s", bindingName)
return Error{
0,
"Binding error",
errDescription,
errorCause,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the full syntax here:

Suggested change
0,
"Binding error",
errDescription,
errorCause,
code: 0,
message: "Binding error",
description: errDescription,
cause: errorCause,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

func CreateForNestedError(functionName string, errorCause error) Error {
errDescription := fmt.Sprintf("Error happened while calling %s", functionName)
return Error{
2,
"Nested error",
errDescription,
errorCause,
}
}

func CommonErrorMissingContract(contractName string) string {
return fmt.Sprintf("Missing needed contract(1) - %s contract not provided", contractName)
}
Loading