Documentation
¶
Index ¶
- func BuildCauseChain(causeErr error, maxDepth int) []string
- func BuildCauseContextChain(causeErr error, maxDepth int) []map[string]any
- func Exit(err *ExitError)
- func IsAlreadyLogged(err error) bool
- func IsHttpException(err error) bool
- func LogContext(err error, extra ...exceptioncontract.Context) exceptioncontract.Context
- func Logged(err error) error
- func MarkLogged(err error) error
- func Panic(err *Error)
- func PanicCause(recoveredValue any) error
- type Error
- func FromError(err error) *Error
- func FromErrorWithLevel(err error, level loggingcontract.Level) *Error
- func FromErrorWithLevelAndContext(err error, level loggingcontract.Level, context exceptioncontract.Context) *Error
- func NewEmergency(message string, context exceptioncontract.Context, causeErr error) *Error
- func NewError(message string, context exceptioncontract.Context, causeErr error) *Error
- func NewInfo(message string, context exceptioncontract.Context, causeErr error) *Error
- func NewWarning(message string, context exceptioncontract.Context, causeErr error) *Error
- func (instance *Error) AlreadyLogged() bool
- func (instance *Error) CauseErr() error
- func (instance *Error) Context() exceptioncontract.Context
- func (instance *Error) Error() string
- func (instance *Error) Level() loggingcontract.Level
- func (instance *Error) MarkAsLogged()
- func (instance *Error) Message() string
- func (instance *Error) SetContext(context exceptioncontract.Context)
- func (instance *Error) SetContextValue(key string, value any)
- func (instance *Error) Unwrap() error
- type ExitError
- type HttpException
- func AsHttpException(err error) *HttpException
- func BadGateway(message string) *HttpException
- func BadRequest(message string) *HttpException
- func Conflict(message string) *HttpException
- func Forbidden(message string) *HttpException
- func GatewayTimeout(message string) *HttpException
- func Gone(message string) *HttpException
- func InternalServerError(message string) *HttpException
- func MethodNotAllowed(message string) *HttpException
- func NewHttpException(statusCode int, message string) *HttpException
- func NewHttpExceptionWithCause(statusCode int, message string, causeErr error) *HttpException
- func NotAcceptable(message string) *HttpException
- func NotFound(message string) *HttpException
- func NotImplemented(message string) *HttpException
- func PaymentRequired(message string) *HttpException
- func RequestTimeout(message string) *HttpException
- func ServiceUnavailable(message string) *HttpException
- func TooManyRequests(message string) *HttpException
- func Unauthorized(message string) *HttpException
- func UnprocessableEntity(message string) *HttpException
- func ValidationFailed(validationErrors any) *HttpException
- func (instance *HttpException) AlreadyLogged() bool
- func (instance *HttpException) CauseErr() error
- func (instance *HttpException) Context() exceptioncontract.Context
- func (instance *HttpException) Error() string
- func (instance *HttpException) MarkAsLogged()
- func (instance *HttpException) Message() string
- func (instance *HttpException) SetContext(context exceptioncontract.Context)
- func (instance *HttpException) SetContextValue(key string, value any)
- func (instance *HttpException) StatusCode() int
- func (instance *HttpException) Unwrap() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildCauseChain ¶ added in v1.9.0
func BuildCauseContextChain ¶ added in v1.9.0
func IsAlreadyLogged ¶ added in v1.19.0
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 ¶
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
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 ¶
MarkLogged marks the nearest AlreadyLogged implementer in the chain — the depth IsAlreadyLogged reads the mark back from — and returns the error unchanged.
func PanicCause ¶ added in v1.19.0
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 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 (*Error) Context ¶
func (instance *Error) Context() exceptioncontract.Context
func (*Error) Level ¶
func (instance *Error) Level() loggingcontract.Level
func (*Error) MarkAsLogged ¶
func (instance *Error) MarkAsLogged()
func (*Error) SetContext ¶
func (instance *Error) SetContext(context exceptioncontract.Context)
func (*Error) SetContextValue ¶
type ExitError ¶
type ExitError struct {
// contains filtered or unexported fields
}
func NewExitError ¶
func (*ExitError) ErrorValue ¶
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