-
Notifications
You must be signed in to change notification settings - Fork 57
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
base: dev
Are you sure you want to change the base?
Changes from 22 commits
08311e1
64d8d09
7156732
f65a3ae
905b68f
6210794
e2c7e03
29302b9
f728fa9
e865d24
0173da5
650ee6d
6a561fa
9770917
f9663e6
db33f93
9be131a
f0a1f0f
0cd9f20
2701a62
c2b8004
8af9063
f971034
6978c58
3839676
3a25ed8
c9c1e74
6ce8886
b56b255
7e6a276
3fda647
1349083
15ed4db
2f4befa
0565335
c4d5c23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||||||||||||||
package elcontracts | ||||||||||||||||||
|
||||||||||||||||||
import "fmt" | ||||||||||||||||||
|
||||||||||||||||||
type Error struct { | ||||||||||||||||||
code int | ||||||||||||||||||
message string | ||||||||||||||||||
description string | ||||||||||||||||||
cause error | ||||||||||||||||||
// metadata map[string]interface{} | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's rename these functions to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use the full syntax here:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||||||||||||||||||
} |
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)