-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Rudrakh Panigrahi <rudrakh97@gmail.com>
- Loading branch information
Showing
3 changed files
with
175 additions
and
23 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,66 @@ | ||
package internal | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// Error is the error type returned by the internal check function | ||
type Error struct { | ||
Code string `json:"code"` | ||
err error `json:"-"` | ||
} | ||
|
||
const ( | ||
|
||
// StartCheckErr error code returned when unable to start new execution | ||
StartCheckErr string = "start_check_error" | ||
|
||
// StartTxnErr error code returned when unable to start new storage transaction | ||
StartTxnErr string = "start_txn_error" | ||
|
||
// RequestParseErr error code returned when unable to parse protobuf request to input map | ||
RequestParseErr string = "request_parse_error" | ||
|
||
// CheckRequestTimeoutErr error code returned when context deadline exceeds before eval | ||
CheckRequestTimeoutErr string = "check_request_timeout" | ||
|
||
// InputParseErr error code returned when unable to convert input map to ast value | ||
InputParseErr string = "input_parse_error" | ||
|
||
// EnvoyAuthEvalErr error code returned when auth eval fails | ||
EnvoyAuthEvalErr string = "envoyauth_eval_error" | ||
|
||
// EnvoyAuthResultErr error code returned when error in fetching result from auth eval | ||
EnvoyAuthResultErr string = "envoyauth_result_error" | ||
) | ||
|
||
// Is allows matching internal errors using errors.Is | ||
func (e *Error) Is(target error) bool { | ||
var t *Error | ||
if errors.As(target, &t) { | ||
return (t.Code == "" || e.Code == t.Code) && errors.Is(e.Unwrap(), t.Unwrap()) | ||
} | ||
return false | ||
} | ||
|
||
// Error allows converting internal Error to string type | ||
func (e *Error) Error() string { | ||
msg := fmt.Sprintf("%v: %v", e.Code, e.Unwrap().Error()) | ||
return msg | ||
} | ||
|
||
// Wrap wraps error as an internal error | ||
func (e *Error) Wrap(err error) *Error { | ||
e.err = err | ||
return e | ||
} | ||
|
||
// Unwrap gets error wrapped in the internal error | ||
func (e *Error) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
func internalError(code string, err error) Error { | ||
return Error{Code: code, err: err} | ||
} |
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
Oops, something went wrong.