exception

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildCauseChain added in v1.9.0

func BuildCauseChain(causeErr error, maxDepth int) []string

func BuildCauseContextChain added in v1.9.0

func BuildCauseContextChain(causeErr error, maxDepth int) []map[string]any

func Exit

func Exit(err *ExitError)

func IsAlreadyLogged added in v1.19.0

func IsAlreadyLogged(err error) bool

IsAlreadyLogged reads the mark at the depth MarkLogged writes it. It is the single reader: reading the mark off a concrete *Error instead misses a marked HttpException and anything wrapping a marked error, which are then rendered a second time.

func IsHttpException

func IsHttpException(err error) bool

IsHttpException answers whether AsHttpException would find a usable exception, so a caller that trusts it and then dereferences cannot meet a disagreement.

func LogContext

func LogContext(err error, extra ...exceptioncontract.Context) exceptioncontract.Context

LogContext assembles the loggable context of an error: its message under "error", the context of the nearest ContextProvider in its chain, the cause chain walked from the error's own wrap link, and every extra map merged on top in order, later entries winning.

func Logged added in v1.19.0

func Logged(err error) error

Logged answers an error that reports itself already logged, and is what a writer returns after filing its record. An error whose chain carries an AlreadyLogged implementer is marked in place and handed back unchanged, so its identity — and every errors.Is and errors.As its readers perform on it — survives. An error whose chain carries none has nowhere for the mark to live: errors.New, fmt.Errorf and every runtime error make MarkLogged a silent no-op, and the next reader then files the same failure a second time. That error is wrapped in a marked melody error keeping it as its cause, so the mark the writer meant to leave is the mark the reader finds. The wrap cannot change how a status is resolved: it happens exactly when no HttpException is in the chain, which is exactly when the status was already going to be the generic one.

func MarkLogged

func MarkLogged(err error) error

MarkLogged marks the nearest AlreadyLogged implementer in the chain — the depth IsAlreadyLogged reads the mark back from — and returns the error unchanged.

func Panic

func Panic(err *Error)

func PanicCause added in v1.19.0

func PanicCause(recoveredValue any) error

PanicCause reads a recovered panic value as the cause of the error a recovery boundary fabricates in its place. An error-shaped panic value belongs in the cause slot, not in a context slot: kept only in the context it collapses to its bare message at the render boundary — the json logger stringifies an error it finds in a context — so the context map and the cause chain of the very error that was raised reach no record at all, and the reason a write failed is gone while the stack that says where survives. A typed nil answers no cause, because its Error() would dereference a nil receiver at the first render, and a panic value that is not an error has no cause to give.

Types

type Error

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

func FromError

func FromError(err error) *Error

func FromErrorWithLevel

func FromErrorWithLevel(err error, level loggingcontract.Level) *Error

func FromErrorWithLevelAndContext added in v1.7.0

func FromErrorWithLevelAndContext(err error, level loggingcontract.Level, context exceptioncontract.Context) *Error

func NewEmergency

func NewEmergency(message string, context exceptioncontract.Context, causeErr error) *Error

func NewError

func NewError(message string, context exceptioncontract.Context, causeErr error) *Error

func NewInfo

func NewInfo(message string, context exceptioncontract.Context, causeErr error) *Error

func NewWarning

func NewWarning(message string, context exceptioncontract.Context, causeErr error) *Error

func (*Error) AlreadyLogged

func (instance *Error) AlreadyLogged() bool

func (*Error) CauseErr

func (instance *Error) CauseErr() error

func (*Error) Context

func (instance *Error) Context() exceptioncontract.Context

func (*Error) Error

func (instance *Error) Error() string

func (*Error) Level

func (instance *Error) Level() loggingcontract.Level

func (*Error) MarkAsLogged

func (instance *Error) MarkAsLogged()

func (*Error) Message

func (instance *Error) Message() string

func (*Error) SetContext

func (instance *Error) SetContext(context exceptioncontract.Context)

func (*Error) SetContextValue

func (instance *Error) SetContextValue(key string, value any)

func (*Error) Unwrap

func (instance *Error) Unwrap() error

type ExitError

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

func NewExitError

func NewExitError(exitCode int, err *Error) *ExitError

func (*ExitError) Error

func (instance *ExitError) Error() string

func (*ExitError) ErrorValue

func (instance *ExitError) ErrorValue() *Error

func (*ExitError) ExitCode

func (instance *ExitError) ExitCode() int

ExitCode answers the nil receiver with the out-of-range 0 rather than dereferencing it: errors.As matches this type on a typed-nil link and reports success with a nil pointer, which the callers that decide how the process ends read the code straight off.

func (*ExitError) Unwrap

func (instance *ExitError) Unwrap() error

type HttpException

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

func AsHttpException

func AsHttpException(err error) *HttpException

func BadGateway

func BadGateway(message string) *HttpException

func BadRequest

func BadRequest(message string) *HttpException

func Conflict

func Conflict(message string) *HttpException

func Forbidden

func Forbidden(message string) *HttpException

func GatewayTimeout

func GatewayTimeout(message string) *HttpException

func Gone

func Gone(message string) *HttpException

func InternalServerError

func InternalServerError(message string) *HttpException

func MethodNotAllowed

func MethodNotAllowed(message string) *HttpException

func NewHttpException

func NewHttpException(statusCode int, message string) *HttpException

func NewHttpExceptionWithCause

func NewHttpExceptionWithCause(statusCode int, message string, causeErr error) *HttpException

func NotAcceptable

func NotAcceptable(message string) *HttpException

func NotFound

func NotFound(message string) *HttpException

func NotImplemented

func NotImplemented(message string) *HttpException

func PaymentRequired

func PaymentRequired(message string) *HttpException

func RequestTimeout

func RequestTimeout(message string) *HttpException

func ServiceUnavailable

func ServiceUnavailable(message string) *HttpException

func TooManyRequests

func TooManyRequests(message string) *HttpException

func Unauthorized

func Unauthorized(message string) *HttpException

func UnprocessableEntity

func UnprocessableEntity(message string) *HttpException

func ValidationFailed

func ValidationFailed(validationErrors any) *HttpException

func (*HttpException) AlreadyLogged

func (instance *HttpException) AlreadyLogged() bool

func (*HttpException) CauseErr

func (instance *HttpException) CauseErr() error

func (*HttpException) Context

func (instance *HttpException) Context() exceptioncontract.Context

func (*HttpException) Error

func (instance *HttpException) Error() string

func (*HttpException) MarkAsLogged

func (instance *HttpException) MarkAsLogged()

func (*HttpException) Message

func (instance *HttpException) Message() string

func (*HttpException) SetContext

func (instance *HttpException) SetContext(context exceptioncontract.Context)

func (*HttpException) SetContextValue

func (instance *HttpException) SetContextValue(key string, value any)

func (*HttpException) StatusCode

func (instance *HttpException) StatusCode() int

func (*HttpException) Unwrap

func (instance *HttpException) Unwrap() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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