errors

package
v0.0.0-...-29e199f Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package errors provides a way to create, manipulate and manage typed errors which contains stack trace information.

All signare code inside the domain and application layers must use it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExists

func IsAlreadyExists(err error) bool

IsAlreadyExists checks whether the target error is of type ErrAlreadyExists.

func IsBadGateway

func IsBadGateway(err error) bool

IsBadGateway checks whether the target error is of type ErrBadGateway.

func IsInternal

func IsInternal(err error) bool

IsInternal checks whether the target error is of type ErrInternal.

func IsInvalidArgument

func IsInvalidArgument(err error) bool

IsInvalidArgument checks whether the target error is of type ErrInvalidArgument.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound checks whether the target error is of type ErrNotFound.

func IsNotImplemented

func IsNotImplemented(err error) bool

IsNotImplemented checks whether the target error is of type ErrNotImplemented.

func IsPermissionDenied

func IsPermissionDenied(err error) bool

IsPermissionDenied checks whether the target error is of type ErrPermissionDenied.

func IsPreconditionFailed

func IsPreconditionFailed(err error) bool

IsPreconditionFailed checks whether the target error is of type ErrPreconditionFailed.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout checks whether the target error is of type ErrTimeout.

func IsTooManyReq

func IsTooManyReq(err error) bool

IsTooManyReq checks whether the target error is of type ErrTooManyReq.

func IsUnauthenticated

func IsUnauthenticated(err error) bool

IsUnauthenticated checks whether the target error is of type ErrUnauthenticated.

func IsUnavailable

func IsUnavailable(err error) bool

IsUnavailable checks whether the target error is of type ErrUnavailable.

Types

type ErrorType

type ErrorType string

ErrorType associated with the PrivateError.

const (
	ErrInvalidArgument    ErrorType = "INVALID_ARGUMENT"
	ErrPreconditionFailed ErrorType = "PRECONDITION_FAILED"
	ErrUnauthenticated    ErrorType = "UNAUTHENTICATED"
	ErrPermissionDenied   ErrorType = "PERMISSION_DENIED"
	ErrNotFound           ErrorType = "NOT_FOUND"
	ErrAlreadyExists      ErrorType = "ALREADY_EXISTS"
	ErrNotImplemented     ErrorType = "NOT_IMPLEMENTED"
	ErrBadGateway         ErrorType = "BAD_GATEWAY"
	ErrUnavailable        ErrorType = "UNAVAILABLE"
	ErrTimeout            ErrorType = "TIMEOUT"
	ErrTooManyReq         ErrorType = "TOO_MANY_REQ"
	ErrInternal           ErrorType = "INTERNAL"
)

func (ErrorType) String

func (et ErrorType) String() string

type PrivateError

type PrivateError struct {
	// contains filtered or unexported fields
}

PrivateError is a traceable error that does not allow to edit the message to explain the reason behind it.

func Internal

func Internal() *PrivateError

Internal returns a new PrivateError of type ErrInternal.

func InternalFromErr

func InternalFromErr(err error) *PrivateError

InternalFromErr returns a new PrivateError of type ErrInternal wrapping the original error.

func PermissionDenied

func PermissionDenied() *PrivateError

PermissionDenied returns a new PrivateError of type ErrPermissionDenied.

func PermissionDeniedFromErr

func PermissionDeniedFromErr(err error) *PrivateError

PermissionDeniedFromErr returns a new PrivateError of type ErrPermissionDenied wrapping the original error.

func (*PrivateError) Error

func (e *PrivateError) Error() string

PrivateError implements the built-in error interface. It returns all available error information, including inner errors that are wrapped by this error.

func (*PrivateError) GetStack

func (e *PrivateError) GetStack() string

GetStack returns the PrivateError's stack trace.

func (*PrivateError) HumanReadableMessage

func (e *PrivateError) HumanReadableMessage() *string

HumanReadableMessage retrieves the message associated with the error or nil if there isn't one. This message may be outputted outside the application.

func (*PrivateError) Type

func (e *PrivateError) Type() ErrorType

Type returns the PrivateError Type

func (*PrivateError) WithMessage

func (e *PrivateError) WithMessage(format string, args ...any) *PrivateError

WithMessage allows to extend the error message.

type PublicError

type PublicError struct {
	PrivateError
}

PublicError is a traceable error that allows to edit the message to explain the reason behind it.

func AlreadyExists

func AlreadyExists() *PublicError

AlreadyExists returns a new PrivateError of type ErrAlreadyExists.

func AlreadyExistsFromErr

func AlreadyExistsFromErr(err error) *PublicError

AlreadyExistsFromErr returns a new PrivateError of type ErrAlreadyExists wrapping the original error.

func BadGateway

func BadGateway() *PublicError

BadGateway returns a new PrivateError of type ErrBadGateway.

func BadGatewayFromErr

func BadGatewayFromErr(err error) *PublicError

BadGatewayFromErr returns a new PrivateError of type ErrBadGateway wrapping the original error.

func InvalidArgument

func InvalidArgument() *PublicError

InvalidArgument returns a new PrivateError of type ErrInvalidArgument.

func InvalidArgumentFromErr

func InvalidArgumentFromErr(err error) *PublicError

InvalidArgumentFromErr returns a new PrivateError of type ErrInvalidArgument wrapping the original error.

func NotFound

func NotFound() *PublicError

NotFound returns a new PrivateError of type ErrNotFound.

func NotFoundFromErr

func NotFoundFromErr(err error) *PublicError

NotFoundFromErr returns a new PrivateError of type ErrNotFound wrapping the original error.

func NotImplemented

func NotImplemented() *PublicError

NotImplemented returns a new PrivateError of type ErrNotImplemented.

func NotImplementedFromErr

func NotImplementedFromErr(err error) *PublicError

NotImplementedFromErr returns a new PrivateError of type ErrNotImplemented wrapping the original error.

func PreconditionFailed

func PreconditionFailed() *PublicError

PreconditionFailed returns a new PrivateError of type ErrPreconditionFailed.

func PreconditionFailedFromErr

func PreconditionFailedFromErr(err error) *PublicError

PreconditionFailedFromErr returns a new PrivateError of type ErrPreconditionFailed wrapping the original error.

func Timeout

func Timeout() *PublicError

Timeout returns a new PrivateError of type ErrTimeout.

func TimeoutFromErr

func TimeoutFromErr(err error) *PublicError

TimeoutFromErr returns a new PrivateError of type ErrTimeout wrapping the original error.

func TooManyReq

func TooManyReq() *PublicError

TooManyReq returns a new PrivateError of type ErrTooManyReq.

func TooManyReqFromErr

func TooManyReqFromErr(err error) *PublicError

TooManyReqFromErr returns a new PrivateError of type ErrTooManyReq wrapping the original error.

func Unauthenticated

func Unauthenticated() *PublicError

Unauthenticated returns a new PrivateError of type ErrUnauthenticated.

func UnauthenticatedFromErr

func UnauthenticatedFromErr(err error) *PublicError

UnauthenticatedFromErr returns a new PrivateError of type ErrUnauthenticated wrapping the original error.

func Unavailable

func Unavailable() *PublicError

Unavailable returns a new PrivateError of type ErrUnavailable.

func UnavailableFromErr

func UnavailableFromErr(err error) *PublicError

UnavailableFromErr returns a new PrivateError of type ErrUnavailable wrapping the original error.

func (*PublicError) SetHumanReadableMessage

func (e *PublicError) SetHumanReadableMessage(format string, args ...any) *PublicError

SetHumanReadableMessage allows to set a message associated with the error that can be read from outside the application. Only UseCases should set human-readable messages.

func (*PublicError) WithMessage

func (e *PublicError) WithMessage(format string, args ...any) *PublicError

WithMessage allows to extend the error message.

type UseCaseError

type UseCaseError interface {
	error
	Type() ErrorType
	GetStack() string
	HumanReadableMessage() *string
}

func CastAsUseCaseError

func CastAsUseCaseError(err error) (UseCaseError, bool)

CastAsUseCaseError casts the provided error as an internal error type

Jump to

Keyboard shortcuts

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