Documentation ¶
Index ¶
- Constants
- func HasErrorCode(err error, code Code) bool
- func IsBenign(err error) (reason string, benign bool)
- func IsNotFoundError(err error) bool
- func IsSilent(err error) bool
- func SetRegistry(r *Registry)
- type Code
- type ErrorConversion
- type Registry
- type SimpleError
- func As(err error) *SimpleError
- func ContextCanceled(err error) *SimpleError
- func ContextDeadlineExceeded(err error) *SimpleError
- func Convert(err error) *SimpleError
- func New(err error) *SimpleError
- func NewNotFoundErrorW(err error, fmt string, args ...interface{}) *SimpleError
- func Newf(_fmt string, args ...interface{}) *SimpleError
- func Wrap(err error, msg string, a ...interface{}) *SimpleError
- func (e *SimpleError) Benign() *SimpleError
- func (e *SimpleError) BenignReason(reason string) *SimpleError
- func (e *SimpleError) Code(code Code) *SimpleError
- func (e *SimpleError) Error() string
- func (e *SimpleError) GetBenignReason() (string, bool)
- func (e *SimpleError) GetCode() Code
- func (e *SimpleError) GetSilent() bool
- func (e *SimpleError) Silence() *SimpleError
- func (e *SimpleError) Unwrap() error
Constants ¶
const NumberOfReservedCodes = 100
NumberOfReservedCodes is the code number, under which, are reserved for use by this library.
Variables ¶
This section is empty.
Functions ¶
func HasErrorCode ¶
HasErrorCode checks the error code of an error if it is a SimpleError{}
func IsNotFoundError ¶
Types ¶
type Code ¶
type Code int
const ( CodeUnknown Code = iota CodeAlreadyExists CodeNotFound CodeNothingUpdated CodeNothingDeleted CodeInvalidParameter CodeInvalidAuth CodeConstraintViolated CodeNotSupported CodeNotImplemented CodeMissingParameter CodeTimedOut CodeCanceled )
These are common impact error codes that are found throughout our services
type ErrorConversion ¶
type ErrorConversion func(err error) *SimpleError
ErrorConversion is a function that converts an `error` into a simple SimpleError{}
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a registry of information on how to handle and serve simple errors
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a new registry without any defaults
func (*Registry) ErrorCodes ¶
ErrorCodes returns a copy of the registered error codes and their descriptions
func (*Registry) RegisterErrorCodes ¶
RegisterErrorCodes registers custom error codes in the registry. This call may panic if a reserved error code is used. This method should be called early on application startup.
func (*Registry) RegisterErrorConversions ¶
func (r *Registry) RegisterErrorConversions(funcs ...ErrorConversion)
RegisterErrorConversions registers an error conversion function
type SimpleError ¶
type SimpleError struct {
// contains filtered or unexported fields
}
SimpleError is an implementation of the `error` interface which provides functionality to ease in the operating and handling of errors in applications.
func As ¶
func As(err error) *SimpleError
As attempts to find a SimpleError in the chain of errors, similar to errors.As()
func ContextCanceled ¶
func ContextCanceled(err error) *SimpleError
func ContextDeadlineExceeded ¶
func ContextDeadlineExceeded(err error) *SimpleError
func Convert ¶
func Convert(err error) *SimpleError
Convert converts a regular error to a SimpleError. If it is already a SimpleError then it simply returns it as a SimpleError
func New ¶
func New(err error) *SimpleError
func NewNotFoundErrorW ¶
func NewNotFoundErrorW(err error, fmt string, args ...interface{}) *SimpleError
func Newf ¶
func Newf(_fmt string, args ...interface{}) *SimpleError
Newf creates a new SimpleError from a formatted string
func Wrap ¶
func Wrap(err error, msg string, a ...interface{}) *SimpleError
Wrap returns a new SimpleError by wrapping an error with a formatted message string
func (*SimpleError) Benign ¶
func (e *SimpleError) Benign() *SimpleError
Benign marks the error as "benign"
func (*SimpleError) BenignReason ¶
func (e *SimpleError) BenignReason(reason string) *SimpleError
BenignReason marks the error as "benign" and attaches a reason it was marked benign.
func (*SimpleError) Code ¶
func (e *SimpleError) Code(code Code) *SimpleError
Code sets the error code. The assigned code should be defined in the registry.
func (*SimpleError) Error ¶
func (e *SimpleError) Error() string
Error satisfies the `error` interface
func (*SimpleError) GetBenignReason ¶
func (e *SimpleError) GetBenignReason() (string, bool)
GetBenignReason returns the benign reason and whether the error was marked as benign
func (*SimpleError) GetCode ¶
func (e *SimpleError) GetCode() Code
GetCode returns the error code as defined in the registry
func (*SimpleError) GetSilent ¶
func (e *SimpleError) GetSilent() bool
GetSilent returns if the error is silent
func (*SimpleError) Silence ¶
func (e *SimpleError) Silence() *SimpleError
Silence sets the error as silent
func (*SimpleError) Unwrap ¶
func (e *SimpleError) Unwrap() error
Unwrap implement the interface required for error unwrapping. It returns the underlying (wrapped) error