errz

package
v19.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextDone

func ContextDone(err error) bool

func DiscardAndClose

func DiscardAndClose(r io.ReadCloser, e *error)

func NewUserError

func NewUserError(msg string) error

func NewUserErrorWithCause

func NewUserErrorWithCause(cause error, msg string) error

func SafeCall

func SafeCall(toCall func() error, err *error)

func SafeClose

func SafeClose(toClose io.Closer, err *error)

Types

type Attachment added in v19.1.0

type Attachment struct {
	Filename    string
	ContentType string
	Payload     []byte
}

Attachment is an arbitrary blob attached to a captured error, such as a goroutine dump.

type CaptureOption added in v19.1.0

type CaptureOption func(*CaptureOptions)

CaptureOption configures a single ErrCapturer.Capture call.

func WithAttachment added in v19.1.0

func WithAttachment(filename, contentType string, payload []byte) CaptureOption

WithAttachment attaches a blob to the captured error.

func WithFields added in v19.1.0

func WithFields(fields ...slog.Attr) CaptureOption

WithFields attaches structured key/value fields to the captured error.

func WithLevel added in v19.1.0

func WithLevel(l Level) CaptureOption

WithLevel sets the severity of the captured error.

type CaptureOptions added in v19.1.0

type CaptureOptions struct {
	Level       Level
	Fields      []slog.Attr
	Attachments []Attachment
}

CaptureOptions is the backend-neutral data accumulated for a captured error.

type ErrCapturer added in v19.1.0

type ErrCapturer interface {
	Capture(ctx context.Context, err error, opts ...CaptureOption)
}

ErrCapturer forwards an error and optional metadata to an error-tracking backend. Unlike ErrReporter it neither logs nor inspects the error; it is the low-level primitive for sending an error report.

type ErrReporter

type ErrReporter interface {
	// HandleProcessingError can be used to handle errors occurring while processing a request.
	// If err is a (or wraps a) errz.UserError, it might be handled specially.
	HandleProcessingError(ctx context.Context, log *slog.Logger, msg string, err error, fields ...slog.Attr)
}

ErrReporter provides a way to report errors.

type Level added in v19.1.0

type Level byte

Level is the backend-neutral severity of a captured error. The zero value is LevelError, the common case.

const (
	LevelError Level = iota
	LevelWarning
)

type UserError

type UserError struct {
	// Message is a textual description of what's wrong.
	// Must be suitable to show to the user.
	Message string
	// Cause optionally holds an underlying error.
	Cause error
}

UserError is an error that happened because the user messed something up: - invalid syntax - invalid configuration

func (UserError) Error

func (e UserError) Error() string

func (UserError) Unwrap

func (e UserError) Unwrap() error

Jump to

Keyboard shortcuts

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