errors

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package errors provides error wrapping with location information

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = errors.ErrUnsupported

ErrUnsupported is errors.ErrUnsupported

Functions

func As

func As(err error, target any) bool

As calls errors.As

func Is

func Is(err error, target error) bool

Is calls errors.Is

func Join

func Join(errs ...error) error

Join calls errors.Join

func Log

func Log(log *slog.Logger, ctx context.Context, level slog.Level, err error, msg string, args ...any)

Log logs err with Source location if Err is a ErrorAt

func New

func New(text string) error

New calls errors.New

func Unwrap

func Unwrap(err error) error

Unwrap calls errors.Unwrap

func Wrap

func Wrap(err error) error

Wrap wraps err in a ErrorAt or returns err if err is nil, already a ErrorAt, or caller info is not available.

XXX: Refactor to Err(error, ...slog.Attr). Often want to add attributes for the top level logger.

Types

type ErrorAt

type ErrorAt struct {
	Err    error
	Source Source
}

ErrorAt wraps an error with the Source location the error was encountered at for tracing from a top level error handler.

func (*ErrorAt) Error

func (e *ErrorAt) Error() string

Error returns the error string with Source location.

func (*ErrorAt) Unwrap

func (e *ErrorAt) Unwrap() error

Unwrap implements error wrapping.

type Source

type Source struct {
	File string `json:"file"`
	Line int    `json:"line"`
}

Source represents the Source file and line where an error was encountered

func (*Source) Loc

func (s *Source) Loc() string

Jump to

Keyboard shortcuts

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