errz

package
v19.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContextDone

func ContextDone(err error) bool

func ContextWithOperation added in v19.4.0

func ContextWithOperation(ctx context.Context, op string) context.Context

ContextWithOperation marks ctx as running op, the logical unit of work that a captured error belongs to. Reporting backends surface it as where the failure happened; it is deliberately not part of how errors are grouped.

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 OperationFromContext added in v19.4.0

func OperationFromContext(ctx context.Context) string

OperationFromContext returns the operation ContextWithOperation put on ctx, or the empty string if the error was captured outside any.

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.

func WithTags added in v19.4.0

func WithTags(tags ...slog.Attr) CaptureOption

WithTags attaches fields that the backend indexes, so they can be searched across errors and broken down within one. Only values from a bounded set belong here: an identifier that ranges freely makes the index useless and costs money to keep. Everything else is WithFields.

type CaptureOptions added in v19.1.0

type CaptureOptions struct {
	Level       Level
	Fields      []slog.Attr
	Tags        []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.

func ErrReporterWithFields added in v19.3.0

func ErrReporterWithFields(rep ErrReporter, fields ...slog.Attr) ErrReporter

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 Named added in v19.4.0

type Named interface {
	error
	ErrorName() string
}

Named is implemented by errors that carry a stable, bounded name for the kind of failure they represent. Error reporting backends group on that name, so it must never contain identifiers, paths or any other per-occurrence data.

type SentinelError added in v19.4.0

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

SentinelError is a package-level error whose name, rather than its message or the call site that reports it, is its identity for error reporting.

func NewSentinelError added in v19.4.0

func NewSentinelError(name, msg string) *SentinelError

func (*SentinelError) Error added in v19.4.0

func (s *SentinelError) Error() string

func (*SentinelError) ErrorName added in v19.4.0

func (s *SentinelError) ErrorName() string

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