errors

package module
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 6 Imported by: 46

README

errors

Go Reference

Custom library to annotate errors.

WARNING: This version is modified to contain the subset of the features we need and will not be useful for the general public.

Install

go get github.com/altipla-consulting/errors

Contributing

You can make pull requests or create issues in GitHub. Any code you send should be formatted using make gofmt.

License

MIT License

Documentation

Overview

Package errors is a custom library to annotate errors.

Based on https://godoc.org/github.com/samsarahq/go/oops and adapted to our function names and needs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As calls errors.As.

func Details

func Details(err error) string

Details returns the stacktrace in a succinct format to print a one-line error.

func Errorf

func Errorf(format string, a ...interface{}) error

Errorf creates a new error with a formatted message.

Use Errorf in places where you would otherwise return an error using fmt.Errorf.

Note that the result of Errorf includes a stacktrace. This means that Errorf is not suitable for storing in global variables. For such errors, keep using errors.New.

func Is

func Is(err, target error) bool

Is calls errors.Is.

func Join added in v1.4.1

func Join(errs ...error) error

Join calls errors.Join.

func LogValue added in v1.3.0

func LogValue(err error) slog.Value

LogValue returns the standard log value to emit the error in a structured way.

func New

func New(text string) error

New calls errors.New.

func Recover

func Recover(p interface{}) error

Recover recovers from a panic in a defer. If there is no panic, Recover() returns nil. To use, call error.Recover(recover()) and compare the result to nil.

func Stack

func Stack(err error) string

Stack returns the stacktrace of an error.

func Trace

func Trace(err error) error

Trace annotates an error with a stacktrace.

Use Trace in places where you would otherwise return an error directly. If the error passed to Trace is nil, Trace will also return nil. This makes it safe to use in one-line return statements.

func Unwrap

func Unwrap(err error) error

Unwrap calls errors.Unwrap.

Types

type Frame

type Frame struct {
	File     string
	Function string
	Line     int
}

Frame stores information about a call stack frame.

func Frames

func Frames(err error) []Frame

Frames extracts all frames from the first altipla error of the chain.

Jump to

Keyboard shortcuts

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