forked from Layr-Labs/eigensdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add error interface from Layr-Labs#477
- Loading branch information
1 parent
041ff96
commit 3b6baca
Showing
1 changed file
with
50 additions
and
0 deletions.
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,50 @@ | ||
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 CreateErrorForMissingContract(contractName string) Error { | ||
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, | ||
} | ||
} | ||
|
||
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) | ||
} |