Merge PR #5240: x/evidence module implementation
This commit is contained in:
@@ -309,6 +309,22 @@ func ResultFromError(err error) Result {
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertError accepts a standard error and attempts to convert it to an sdk.Error.
|
||||
// If the given error is already an sdk.Error, it'll simply be returned. Otherwise,
|
||||
// it'll convert it to a types.Error. This is meant to provide a migration path
|
||||
// away from sdk.Error in favor of types.Error.
|
||||
func ConvertError(err error) Error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if sdkError, ok := err.(Error); ok {
|
||||
return sdkError
|
||||
}
|
||||
|
||||
space, code, log := sdkerrors.ABCIInfo(err, false)
|
||||
return NewError(CodespaceType(space), CodeType(code), log)
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
// REST error utilities
|
||||
|
||||
|
||||
+11
-1
@@ -65,6 +65,12 @@ var (
|
||||
// ErrNoSignatures to doc
|
||||
ErrNoSignatures = Register(RootCodespace, 16, "no signatures supplied")
|
||||
|
||||
// ErrJSONMarshal defines an ABCI typed JSON marshalling error
|
||||
ErrJSONMarshal = Register(RootCodespace, 17, "failed to marshal JSON bytes")
|
||||
|
||||
// ErrJSONUnmarshal defines an ABCI typed JSON unmarshalling error
|
||||
ErrJSONUnmarshal = Register(RootCodespace, 18, "failed to unmarshal JSON bytes")
|
||||
|
||||
// ErrPanic is only set when we recover from a panic, so we know to
|
||||
// redact potentially sensitive system info
|
||||
ErrPanic = Register(UndefinedCodespace, 111222, "panic")
|
||||
@@ -121,7 +127,7 @@ func ABCIError(codespace string, code uint32, log string) error {
|
||||
}
|
||||
// This is a unique error, will never match on .Is()
|
||||
// Use Wrap here to get a stack trace
|
||||
return Wrap(&Error{codespace: codespace, code: code, desc: "unknown"}, log)
|
||||
return Wrap(New(codespace, code, "unknown"), log)
|
||||
}
|
||||
|
||||
// Error represents a root error.
|
||||
@@ -139,6 +145,10 @@ type Error struct {
|
||||
desc string
|
||||
}
|
||||
|
||||
func New(codespace string, code uint32, desc string) *Error {
|
||||
return &Error{codespace: codespace, code: code, desc: desc}
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return e.desc
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package types
|
||||
|
||||
import "regexp"
|
||||
|
||||
// IsAlphaNumeric defines a regular expression for matching against alpha-numeric
|
||||
// values.
|
||||
var IsAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString
|
||||
|
||||
// Router provides handlers for each transaction type.
|
||||
type Router interface {
|
||||
AddRoute(r string, h Handler) Router
|
||||
|
||||
Reference in New Issue
Block a user