Documentation ¶
Index ¶
- Constants
- Variables
- func ABCIError(code uint32, log string) error
- func ABCIInfo(err error, debug bool) (uint32, string)
- func Append(errs ...error) error
- func AppendField(errorsOrNil error, fieldName string, fieldErrOrNil error) error
- func Field(fieldName string, err error, description string, args ...interface{}) error
- func FieldErrors(err error, fieldName string) []error
- func Recover(err *error)
- func Redact(err error) error
- func WithType(err error, obj interface{}) error
- func Wrap(err error, description string) error
- func Wrapf(err error, format string, args ...interface{}) error
- type Error
Constants ¶
const ( // SuccessABCICode declares an ABCI response use 0 to signal that the // processing was successful and no error is returned. SuccessABCICode = 0 )
Variables ¶
var ( // authorization is handled. ErrUnauthorized = Register(2, "unauthorized") // ErrNotFound is used when a requested operation cannot be completed // due to missing data. ErrNotFound = Register(3, "not found") // ErrMsg is returned whenever an event is invalid and cannot be // handled. ErrMsg = Register(4, "invalid message") // ErrModel is returned whenever a message is invalid and cannot // be used (ie. persisted). ErrModel = Register(5, "invalid model") // ErrDuplicate is returned when there is a record already that has the same // unique key/index used ErrDuplicate = Register(6, "duplicate") // ErrHuman is returned when application reaches a code path which should not // ever be reached if the code was written as expected by the framework ErrHuman = Register(7, "coding error") // ErrImmutable is returned when something that is considered immutable // gets modified ErrImmutable = Register(8, "cannot be modified") // ErrEmpty is returned when a value fails a not empty assertion ErrEmpty = Register(9, "value is empty") // ErrState is returned when an object is in invalid state ErrState = Register(10, "invalid state") // ErrType is returned whenever the type is not what was expected ErrType = Register(11, "invalid type") // ErrAmount is returned when processed amount is invalid. ErrAmount = Register(13, "invalid amount") // ErrInput stands for general input problems indication ErrInput = Register(14, "invalid input") // ErrExpired stands for expired entities, normally has to do with block height expirations ErrExpired = Register(15, "expired") // ErrOverflow s returned when a computation cannot be completed // because the result value exceeds the type. ErrOverflow = Register(16, "an operation cannot be completed due to value overflow") // ErrCurrency is returned whenever an operation cannot be completed // due to a currency issues. ErrCurrency = Register(17, "currency") // ErrMetadata is returned whenever a weave.Metadata payload is invalid. ErrMetadata = Register(18, "metadata") // ErrSchema is returned whenever an operation cannot be completed due // to an object schema version issue. ErrSchema = Register(19, "schema") // ErrDatabase is returned whenever the underlying kvstore fails to // process raw bytes (get/set/delete/write) ErrDatabase = Register(20, "database") // ErrDeleted is returned whenever a deleted object version is accessed. ErrDeleted = Register(21, "content deleted") // ErrIteratorDone is returned when an iterator hits the end of the data source. ErrIteratorDone = Register(22, "iterator done") // ErrChain is returned when an operation cannot be completed because // it cannot be executed on the current chain ErrChain = Register(23, "invalid chain") // ErrNetwork is returned on network failure (only for client libraries) ErrNetwork = Register(100200, "network") // ErrTimeout is returned on context timeout (only for client libraries) ErrTimeout = Register(100300, "timeout") // ErrPanic is only set when we recover from a panic, so we know to // redact potentially sensitive system info ErrPanic = Register(111222, "panic") )
Functions ¶
func ABCIError ¶ added in v0.15.0
ABCIError will resolve an error code/log from an abci result into an error message. If the code is registered, it will map it back to the canonical error, so we can do eg. ErrNotFound.Is(err) on something we get back from an external API.
This should *only* be used in clients, not in the server side. The server (abci app / blockchain) should only refer to registered errors
func ABCIInfo ¶ added in v0.12.1
ABCIInfo returns the ABCI error information as consumed by the tendermint client. Returned code and log message should be used as a ABCI response. Any error that does not provide ABCICode information is categorized as error with code 1. When not running in a debug mode all messages of errors that do not provide ABCICode information are replaced with generic "internal error". Errors without an ABCICode information as considered internal.
func Append ¶ added in v0.16.0
Append clubs together all provided errors. Nil values are ignored.
If given error implements unpacker interface, it is flattened. All represented by this error container errors are directly included into the result set rather than through the container. This means that
Append(Append(err1, err2), Append(err3), err4)
produce the same result as
Append(err1, err2, err3, err4)
Because not all errors implement unpacker interface, the internal representation of the constructed error relation can be a tree. For example, the following code will result in a tree-like error chain.
Append(err1, Wrap(Append(err2, err3), "w"))
When implementing an error that satisfies unpacker interface, keep in mind that Append function destroys such error and consume only contained by it errors. Implement unpacker interface only for error containers, that do not carry any additional information.
func AppendField ¶ added in v0.17.0
AppendField is a shortcut function to club together error(s) with a given field error.
Use Go naming for the field name. For example, UserName or MaxAge. When the error is for a nested field, use dot notation to constrct the path. For example, User.Age or User.Name. When the path includes an iterable, use the element index starting with 0 as the name, for example Tags.0 or Profiles.2.ID
func Field ¶ added in v0.17.0
Field returns an error instance that wraps the original error with additional information. It returns `nil` if provided error is `nil`. Use this function to create an error instance describing a field/attribute error. This function might attach a stack trace information.
Use Go naming for the field name. For example, UserName or MaxAge. When the error is for a nested field, use dot notation to constrct the path. For example, User.Age or User.Name. When the path includes an iterable, use the element index starting with 0 as the name, for example Tags.0 or Profiles.2.ID
func FieldErrors ¶ added in v0.17.0
FieldErrors returns the list of all errors that are created for the given field name. An error must be implementing a fielder interface and return a matching field name in order to pass the test and be included in the result set.
func Recover ¶
func Recover(err *error)
Recover captures a panic and stop its propagation. If panic happens it is transformed into a ErrPanic instance and assigned to given error. Call this function using defer in order to work as expected.
func Redact ¶ added in v0.12.0
Redact replace all errors that do not initialize with a weave error with a generic internal error instance. This function is supposed to hide implementation details errors and leave only those that weave framework originates.
func WithType ¶ added in v0.12.0
WithType is a helper to augment an error with a corresponding type message
func Wrap ¶
Wrap extends given error with an additional information.
If the wrapped error does not provide ABCICode method (ie. stdlib errors), it will be labeled as internal error.
If err is nil, this returns nil, avoiding the need for an if statement when wrapping a error returned at the end of a function
Types ¶
type Error ¶ added in v0.12.0
type Error struct {
// contains filtered or unexported fields
}
Error represents a root error.
Weave framework is using root error to categorize issues. Each instance created during the runtime should wrap one of the declared root errors. This allows error tests and returning all errors to the client in a safe manner.
All popular root errors are declared in this package. If an extension has to declare a custom root error, always use Register function to ensure error code uniqueness.
func Register ¶ added in v0.12.0
Register returns an error instance that should be used as the base for creating error instances during runtime.
Popular root errors are declared in this package, but extensions may want to declare custom codes. This function ensures that no error code is used twice. Attempt to reuse an error code results in panic.
Use this function only during a program startup phase.