errors

package module
v0.0.0-...-6077fa9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 13 Imported by: 20

README

MIT Licensed Build Status Test Coverage Go Report Card

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	As     = errors.As
	Is     = errors.Is
	Unwrap = errors.Unwrap
)

Export a number of functions or variables from package errors.

View Source
var IncludeBacktrace = true

IncludeBacktrace is a static variable that decides if when creating an error we store the backtrace with it.

View Source
var Join = errors.Join
View Source
var NotFound = ErrorHandlerFn(func(w http.ResponseWriter, r *http.Request) error {
	return NotFoundf("%s not found", r.URL.Path)
})

NotFound is a generic method to return an 404 error HTTP handler that

Functions

func AnnotateFromStatus

func AnnotateFromStatus(err error, status int, s string, args ...interface{}) error

func BadGatewayf

func BadGatewayf(s string, args ...interface{}) *badGateway

func BadRequestf

func BadRequestf(s string, args ...interface{}) *badRequest

func Challenge

func Challenge(err error) string

Challenge returns the challenge of the err parameter if it's an unauthorized type error

func Conflictf

func Conflictf(s string, args ...interface{}) *conflict

func Errorf

func Errorf(s string, args ...interface{}) error

Errorf is an alias for Newf

func Forbiddenf

func Forbiddenf(s string, args ...interface{}) *forbidden

func FromResponse

func FromResponse(resp *http.Response) error

func Gonef

func Gonef(s string, args ...interface{}) *gone

func HttpStatus

func HttpStatus(e error) int

func IsBadGateway

func IsBadGateway(e error) bool

func IsBadRequest

func IsBadRequest(e error) bool

func IsConflict

func IsConflict(e error) bool

func IsForbidden

func IsForbidden(e error) bool

func IsGone

func IsGone(e error) bool

func IsMethodNotAllowed

func IsMethodNotAllowed(e error) bool

func IsNotFound

func IsNotFound(e error) bool

func IsNotImplemented

func IsNotImplemented(e error) bool

func IsNotSupported

func IsNotSupported(e error) bool

func IsNotValid

func IsNotValid(e error) bool

func IsTimeout

func IsTimeout(e error) bool

func IsUnauthorized

func IsUnauthorized(e error) bool

func MethodNotAllowedf

func MethodNotAllowedf(s string, args ...interface{}) *methodNotAllowed

func NewBadGateway

func NewBadGateway(e error, s string, args ...interface{}) *badGateway

func NewBadRequest

func NewBadRequest(e error, s string, args ...interface{}) *badRequest

func NewConflict

func NewConflict(e error, s string, args ...interface{}) *conflict

func NewForbidden

func NewForbidden(e error, s string, args ...interface{}) *forbidden

func NewFromStatus

func NewFromStatus(status int, s string, args ...interface{}) error

func NewGone

func NewGone(e error, s string, args ...interface{}) *gone

func NewMethodNotAllowed

func NewMethodNotAllowed(e error, s string, args ...interface{}) *methodNotAllowed

func NewNotFound

func NewNotFound(e error, s string, args ...interface{}) *notFound

func NewNotImplemented

func NewNotImplemented(e error, s string, args ...interface{}) *notImplemented

func NewNotSupported

func NewNotSupported(e error, s string, args ...interface{}) *notSupported

func NewNotValid

func NewNotValid(e error, s string, args ...interface{}) *notValid

func NewTimeout

func NewTimeout(e error, s string, args ...interface{}) *timeout

func NewUnauthorized

func NewUnauthorized(e error, s string, args ...interface{}) *unauthorized

func NotFoundf

func NotFoundf(s string, args ...interface{}) *notFound

func NotImplementedf

func NotImplementedf(s string, args ...interface{}) *notImplemented

func NotSupportedf

func NotSupportedf(s string, args ...interface{}) *notSupported

func NotValidf

func NotValidf(s string, args ...interface{}) *notValid

func RenderErrors

func RenderErrors(r *http.Request, errs ...error) (int, []byte)

RenderErrors outputs the json encoded errors, with the JsonLD ctxt for current

func Timeoutf

func Timeoutf(s string, args ...interface{}) *timeout

func Unauthorizedf

func Unauthorizedf(s string, args ...interface{}) *unauthorized

func WrapWithStatus

func WrapWithStatus(status int, err error, s string, args ...interface{}) error

Types

type Err

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

Err is our custom error type that can store backtrace, file and line number

func Annotatef

func Annotatef(e error, s string, args ...interface{}) *Err

Annotatef wraps an error with new message

func Newf

func Newf(s string, args ...interface{}) *Err

Newf creaates a new error

func (*Err) As

func (e *Err) As(err interface{}) bool

As implements support for errors.As

func (Err) Error

func (e Err) Error() string

Error implements the error interface

func (Err) Format

func (e Err) Format(s fmt.State, verb rune)

func (Err) StackTrace

func (e Err) StackTrace() StackTrace

StackTrace returns the stack trace as returned by the debug.Stack function

func (*Err) UnmarshalJSON

func (e *Err) UnmarshalJSON(data []byte) error

func (Err) Unwrap

func (e Err) Unwrap() error

Unwrap implements the errors.Wrapper interface

type Error

type Error interface {
	error
	json.Unmarshaler
}

func UnmarshalJSON

func UnmarshalJSON(data []byte) ([]Error, error)

type ErrorHandlerFn

type ErrorHandlerFn func(http.ResponseWriter, *http.Request) error

ErrorHandlerFn

func HandleError

func HandleError(e error) ErrorHandlerFn

HandleError is a generic method to return an HTTP handler that passes an error up the chain

func (ErrorHandlerFn) ServeHTTP

func (h ErrorHandlerFn) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface for the ItemHandlerFn type

type Frame

type Frame uintptr

Frame represents a program counter inside a stack frame. For historical reasons if Frame is interpreted as a uintptr its value represents the program counter + 1.

func (Frame) Format

func (f Frame) Format(s fmt.State, verb rune)

Format formats the frame according to the fmt.Formatter interface.

%s    source file
%d    source line
%n    function name
%v    equivalent to %s:%d

Format accepts flags that alter the printing of some verbs, as follows:

%+s   function name and path of source file relative to the compile time
      GOPATH separated by \n\t (<funcname>\n\t<path>)
%+v   equivalent to %+s:%d

func (Frame) MarshalJSON

func (f Frame) MarshalJSON() ([]byte, error)

func (Frame) MarshalText

func (f Frame) MarshalText() ([]byte, error)

MarshalText formats a stacktrace Frame as a text string. The output is the same as that of fmt.Sprintf("%+v", f), but without newlines or tabs.

type Http

type Http struct {
	Code    int        `jsonld:"status,omitempty"`
	Message string     `jsonld:"message"`
	Trace   StackTrace `jsonld:"trace,omitempty"`
}

func HttpErrors

func HttpErrors(err error) []Http

type StackTrace

type StackTrace []Frame

StackTrace is stack of Frames from innermost (newest) to outermost (oldest).

func (StackTrace) Format

func (st StackTrace) Format(s fmt.State, verb rune)

Format formats the stack of Frames according to the fmt.Formatter interface.

%s	lists source files for each Frame in the stack
%v	lists the source file and line number for each Frame in the stack

Format accepts flags that alter the printing of some verbs, as follows:

%+v   Prints filename, function, and line number for each Frame in the stack.

func (StackTrace) MarshalJSON

func (st StackTrace) MarshalJSON() ([]byte, error)

type StackTracer

type StackTracer interface {
	StackTrace() StackTrace
}

Jump to

Keyboard shortcuts

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