Skip to content

Commit

Permalink
Add error interface from Layr-Labs#477
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli committed Jan 29, 2025
1 parent 041ff96 commit 3b6baca
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions chainio/clients/elcontracts/error.go
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)
}

0 comments on commit 3b6baca

Please sign in to comment.