errors

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 8 Imported by: 1

README

go-errors

Errors with stack traces.

Based on other packages that do the same. I use these in my personal projects, this package isn't intended to be used by others.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var As = errors.As
View Source
var Is = errors.Is
View Source
var Join = errors.Join
View Source
var New = errors.New
View Source
var Unwrap = errors.Unwrap

Functions

func AsType added in v0.0.4

func AsType[E error](err error) (E, bool)

func ErrorCodef added in v0.0.2

func ErrorCodef(code StatusCode, format string, args ...any) error

Error with a code and internal message.

func ErrorMessage added in v0.0.2

func ErrorMessage(code StatusCode, message string) error

func ErrorMessagef added in v0.0.2

func ErrorMessagef(code StatusCode, message string, args ...any) error

Error with a publicly visible message.

func ErrorPayload added in v0.0.2

func ErrorPayload(code StatusCode, payload any) error

Error with a payload.

func Errorf

func Errorf(format string, args ...any) error

func FailJSON added in v0.0.2

func FailJSON(w http.ResponseWriter, r *http.Request, err error)

func HTTPCode added in v0.0.2

func HTTPCode(code StatusCode) int

func HTTPCodeMessage added in v0.0.2

func HTTPCodeMessage(code StatusCode, message string) (int, string)

func HasStack

func HasStack(err error) bool

func HelperErrorf added in v0.0.2

func HelperErrorf(format string, args ...any) error

func Payload added in v0.0.2

func Payload(err error) any

func WithCode added in v0.0.2

func WithCode(code StatusCode, message string, cause error) error

func WithCodeStack added in v0.0.2

func WithCodeStack(code StatusCode, message string, cause error) error

func WithStack

func WithStack(err error) error

Types

type StatusCode added in v0.0.2

type StatusCode int
const (
	StatusUnknown StatusCode = iota
	StatusCanceled
	StatusInvalidArgument
	StatusDeadlineExceeded
	StatusInternal
	StatusNotFound
	StatusUnauthenticated
	StatusPermissionDenied
	StatusAlreadyExists
	StatusFailedPrecondition
	StatusUnimplemented
)

Union of HTTP status codes & https://grpc.github.io/grpc/core/md_doc_statuscodes.html If you add a value here, search for all switches on this enum.

func Code added in v0.0.2

func Code(err error) (StatusCode, string)

func Status added in v0.0.2

func Status(err error) StatusCode

Jump to

Keyboard shortcuts

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