errors

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2022 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeactivateLocation = false

DeactivateLocation allow to not execute the code for retrieving location of errors since this is not a free operation.

View Source
var KindToStatusCodeHook = func(k Kind) int {
	return http.StatusInternalServerError
}

KindToStatusCodeHook is here for you, you can override this to add custom kind with custom status code

Functions

This section is empty.

Types

type Error

type Error struct {

	// Kind represent the type of error
	Kind Kind

	// Message is the information about the error
	Message string

	// Err is the wrapped error
	Err error
	// contains filtered or unexported fields
}

Error is the represented error and underlying errors too

func New

func New(format string, i ...interface{}) *Error

New create a new error By default the kind is KindInternal

func NewWithKind

func NewWithKind(kind Kind, format string, i ...interface{}) *Error

NewWithKind create a new error with a kind

func Wrap

func Wrap(err error, format string, i ...interface{}) *Error

Wrap the raw error with a descriptive message By default the kind is KindInternal

func WrapWithKind

func WrapWithKind(kind Kind, err error, format string, i ...interface{}) *Error

WrapWithKind the raw error with a descriptive message with custom kind

func (*Error) Error

func (e *Error) Error() string

Error return the error as string with the underlying errors

func (*Error) GetField

func (e *Error) GetField(key string) (value interface{}, ok bool)

GetField get a field by its key

func (*Error) Log

func (e *Error) Log() *logrus.Entry

Log is a shortcut to log an error

func (*Error) Stacktrace

func (e *Error) Stacktrace() string

Stacktrace format a pretty printed stacktrace of the errors

func (*Error) WithField

func (e *Error) WithField(key string, value interface{}) *Error

WithField add a field

func (*Error) WithFields

func (e *Error) WithFields(m map[string]interface{}) *Error

WithFields add fields

func (*Error) WithKind

func (e *Error) WithKind(kind Kind) *Error

WithKind set the kind

func (*Error) WithMessage

func (e *Error) WithMessage(format string, i ...interface{}) *Error

WithMessage set the message

func (*Error) WithOpHere

func (e *Error) WithOpHere() *Error

WithOpHere relocalise the error where this function is called

type Kind

type Kind string

Kind represent an error type

const (
	// KindCanceled indicates the location was cancelled (typically by the caller).
	KindCanceled Kind = "canceled"

	// KindUnknown error. For example when handling errors raised by APIs that do not
	// return enough error information.
	KindUnknown Kind = "unknown"

	// KindInvalidArgument indicates client specified an invalid argument. It
	// indicates arguments that are problematic regardless of the state of the
	// system (i.e. a malformed file name, required argument, number out of range,
	// etc.).
	KindInvalidArgument Kind = "invalid_argument"

	// KindDeadlineExceeded means location expired before completion. For locations
	// that change the state of the system, this error may be returned even if the
	// location has completed successfully (timeout).
	KindDeadlineExceeded Kind = "deadline_exceeded"

	// KindNotFound means some requested entity was not found.
	KindNotFound Kind = "not_found"

	// KindAlreadyExists means an attempt to create an entity failed because one
	// already exists.
	KindAlreadyExists Kind = "already_exists"

	// KindPermissionDenied indicates the caller does not have permission to execute
	// the specified location. It must not be used if the caller cannot be
	// identified (Unauthenticated).
	KindPermissionDenied Kind = "permission_denied"

	// KindUnauthenticated indicates the request does not have valid authentication
	// credentials for the location.
	KindUnauthenticated Kind = "unauthenticated"

	// KindResourceExhausted indicates some resource has been exhausted, perhaps a
	// per-user quota, or perhaps the entire file system is out of space.
	KindResourceExhausted Kind = "resource_exhausted"

	// KindFailedPrecondition indicates location was rejected because the system is
	// not in a state required for the location's execution. For example, doing
	// an rmdir location on a directory that is non-empty, or on a non-directory
	// object, or when having conflicting read-modify-write on the same resource.
	KindFailedPrecondition Kind = "failed_precondition"

	// KindAborted indicates the location was aborted, typically due to a concurrency
	// issue like sequencer check failures, transaction aborts, etc.
	KindAborted Kind = "aborted"

	// KindOutOfRange means location was attempted past the valid range. For example,
	// seeking or reading past end of a paginated collection.
	//
	// Unlike InvalidArgument, this error indicates a problem that may be fixed if
	// the system state changes (i.e. adding more items to the collection).
	//
	// There is a fair bit of overlap between FailedPrecondition and OutOfRange.
	// We recommend using OutOfRange (the more specific error) when it applies so
	// that callers who are iterating through a space can easily look for an
	// OutOfRange error to detect when they are done.
	KindOutOfRange Kind = "out_of_range"

	// KindUnimplemented indicates location is not implemented or not
	// supported/enabled in this service.
	KindUnimplemented Kind = "unimplemented"

	// KindInternal errors. When some invariants expected by the underlying system
	// have been broken. In other words, something bad happened in the library or
	// backend service. Do not confuse with HTTP Internal Server Error; an
	// Internal error could also happen on the client code, i.e. when parsing a
	// server response.
	KindInternal Kind = "internal"

	// KindUnavailable indicates the service is currently unavailable. This is a most
	// likely a transient condition and may be corrected by retrying with a
	// backoff.
	KindUnavailable Kind = "unavailable"

	// KindDataLoss indicates unrecoverable data loss or corruption.
	KindDataLoss Kind = "data_loss"

	// KindNone is the zero-value, is considered an empty error and should not be
	// used.
	KindNone Kind = ""
)

func (Kind) ToStatusCode

func (k Kind) ToStatusCode() int

ToStatusCode convert a kind to a http status code (int) If the kind is not recognized the KindToStatusCodeHook will be executed

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL