errs

package module
v0.0.0-...-1a4fc35 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: MIT Imports: 3 Imported by: 0

README

Go Reference Report card

errs

errs defines a set of common application errors, built on top of cockroachdb/errors.

Installation

go get github.com/LightArrayCapital/go-utilities/errs

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NotFound is returned when a resource is not found
	NotFound = errors.NewWithDepth(depth, "not found")

	// InternalError is returned when internal logic got error
	InternalError = errors.NewWithDepth(depth, "internal error")

	// SomethingWentWrong is returned when got some bug or unexpected case
	//
	// inherited error from InternalError,
	// so errors.Is(err, InternalError) == true
	SomethingWentWrong = errors.WrapWithDepth(depth, InternalError, "something went wrong")

	// Skippable is returned when got an error but it can be skipped or ignored and continue
	Skippable = errors.NewWithDepth(depth, "skippable")

	// Retryable is returned when got an error but it can be retried
	Retryable = errors.NewWithDepth(depth, "retryable")

	// Unsupported is returned when a feature or result is not supported
	Unsupported = errors.NewWithDepth(depth, "unsupported")

	// NotSupported is returned when a feature or result is not supported
	// alias of Unsupported
	NotSupported = Unsupported

	// Unauthorized is returned when a request is unauthorized
	Unauthorized = errors.NewWithDepth(depth, "unauthorized")

	// Timeout is returned when a connection to a resource timed out
	Timeout = errors.NewWithDepth(depth, "timeout")

	// BadRequest is returned when a request is invalid
	BadRequest = errors.NewWithDepth(depth, "bad request")

	// InvalidArgument is returned when an argument is invalid
	//
	// inherited error from BadRequest,
	// so errors.Is(err, BadRequest) == true
	InvalidArgument = errors.WrapWithDepth(depth, BadRequest, "invalid argument")

	// ArgumentRequired is returned when an argument is required
	//
	// inherited error from BadRequest,
	// so errors.Is(err, BadRequest) == true
	ArgumentRequired = errors.WrapWithDepth(depth, BadRequest, "argument required")

	// Duplicate is returned when a resource already exists
	Duplicate = errors.NewWithDepth(depth, "duplicate")

	// Unimplemented is returned when a feature or method is not implemented
	//
	// inherited error from Unsupported,
	// so errors.Is(err, Unsupported) == true
	Unimplemented = errors.WrapWithDepth(depth, Unsupported, "unimplemented")

	// Unavailable is returned when a resource is unavailable
	Unavailable = errors.NewWithDepth(depth, "unavailable")

	// RateLimitExceeded is returned when a rate limit is exceeded
	RateLimitExceeded = errors.NewWithDepth(depth, "rate limit exceeded")

	// Overflow is returned when an overflow error occurs
	//
	// inherited error from InternalError,
	// so errors.Is(err, InternalError) == true
	Overflow = errors.WrapWithDepth(depth, InternalError, "overflow")

	// InvalidState is returned when a state is invalid
	InvalidState = errors.NewWithDepth(depth, "invalid state")

	// Closed is returned when a resource is closed
	Closed = errors.NewWithDepth(depth, "closed")
)

Common Application Errors

Functions

func NewPublicError

func NewPublicError(message string) error

func NewPublicErrorWithCode

func NewPublicErrorWithCode(message string, code string) error

func WithPublicMessage

func WithPublicMessage(err error, prefix string) error

func WithPublicMessageCode

func WithPublicMessageCode(err error, prefix string, code string) error

Types

type PublicError

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

PublicError is an error that, when caught by an error handler, should return a user-friendly error response to the user. Responses vary between each protocol (http, grpc, etc.) and between each error handler implementation.

func (PublicError) Code

func (p PublicError) Code() string

func (PublicError) Error

func (p PublicError) Error() string

func (PublicError) Message

func (p PublicError) Message() string

func (PublicError) Unwrap

func (p PublicError) Unwrap() error

Jump to

Keyboard shortcuts

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