Documentation ¶
Overview ¶
Package commonerrors defines typical errors which can happen.
Index ¶
- Constants
- Variables
- func Any(target error, err ...error) bool
- func ConvertContextError(err error) error
- func CorrespondTo(target error, description ...string) bool
- func DeserialiseError(text []byte) (deserialisedError, err error)
- func Ignore(target error, ignore ...error) error
- func IsCommonError(target error) bool
- func IsEmpty(err error) bool
- func IsWarning(target error) bool
- func NewWarning(target error) (ok bool, err error)
- func None(target error, err ...error) bool
- func ParseWarning(target error) (ok bool, err error)
- func RelatesTo(target string, errors ...error) bool
- func SerialiseError(err error) ([]byte, error)
Constants ¶
const ( TypeReasonErrorSeparator = ':' MultipleErrorSeparator = '\n' )
Variables ¶
var ( ErrNotImplemented = errors.New("not implemented") ErrNoExtension = errors.New("missing extension") ErrNoLogger = errors.New("missing logger") ErrNoLoggerSource = errors.New("missing logger source") ErrNoLogSource = errors.New("missing log source") ErrUndefined = errors.New("undefined") ErrInvalidDestination = errors.New("invalid destination") ErrTimeout = errors.New("timeout") ErrLocked = errors.New("locked") ErrStaleLock = errors.New("stale lock") ErrExists = errors.New("already exists") ErrNotFound = errors.New("not found") ErrUnsupported = errors.New("unsupported") ErrWrongUser = errors.New("wrong user") ErrUnknown = errors.New("unknown") ErrInvalid = errors.New("invalid") ErrConflict = errors.New("conflict") ErrMarshalling = errors.New("unserialisable") ErrCancelled = errors.New("cancelled") ErrEmpty = errors.New("empty") ErrUnexpected = errors.New("unexpected") ErrTooLarge = errors.New("too large") ErrForbidden = errors.New("forbidden") ErrCondition = errors.New("failed condition") ErrEOF = errors.New("end of file") ErrMalicious = errors.New("suspected malicious intent") ErrOutOfRange = errors.New("out of range") // ErrWarning is a generic error that can be used when an error should be raised but it shouldn't necessary be // passed up the chain, for example in cases where an error should be logged but the program should continue. In // these situations it should be handled immediately and then ignored/set to nil. ErrWarning = errors.New(warningStr) )
List of common errors used to qualify and categorise go errors Note: if adding error types to this list, ensure mapping functions (below) are also updated.
Functions ¶
func ConvertContextError ¶
ConvertContextError converts a context error into common errors.
func CorrespondTo ¶ added in v1.29.0
CorrespondTo determines whether a `target` error corresponds to a specific error described by `description` It will check whether the error contains the string in its description. It is not case-sensitive. ```code
CorrespondTo(errors.New("feature a is not supported"), "not supported") = True ```
func DeserialiseError ¶ added in v1.45.0
DeserialiseError unmarshals text into an error. It tries to determine the error type.
func Ignore ¶ added in v1.32.0
Ignore will return nil if the target error matches one of the errors to ignore
func IsCommonError ¶ added in v1.64.0
IsCommonError returns whether an error is a commonerror
func IsEmpty ¶ added in v1.45.0
IsEmpty states whether an error is empty or not. An error is considered empty if it is `nil` or has no description.
func NewWarning ¶ added in v1.64.0
NewWarning will create a warning wrapper around an existing commonerror so that it can be easily recovered. If the underlying error is not a commonerror then ok will be set to false
func ParseWarning ¶ added in v1.64.0
ParseWarning will extract the error that has been wrapped by ErrWarning. It will return nil if the error was not one of ErrWarning with ok set to false. It will also set ok to false if the underlying error cannot be parsed
func RelatesTo ¶ added in v1.66.0
RelatesTo determines whether an error description string could relate to a particular set of common errors This assumes that the error description follows the convention of placing the type of errors at the start of the string.
func SerialiseError ¶ added in v1.45.0
SerialiseError marshals an error following a certain convention: `error type: reason`.
Types ¶
This section is empty.