errors

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: BSD-3-Clause Imports: 4 Imported by: 0

README

errors

errors package is a wrapper around Go's errors package. It provides a way to wrap errors with additional context about where the error occurred.

It's a simple package to avoid the need to write the following boilerplate to make errors easier to track.

if _, err := os.Open("non-existent-file"); err != nil {
	return fmt.Errorf("os.Remove: %w", err)
}

Instead, you can write:

if _, err := os.Open("non-existent-file"); err != nil {
	return errors.Wrap(err)
}

The error will be wrapped with the file and line number where the error occurred. Error will return a string like:

example.go:17: file does not exist

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As(err error, target any) bool

As is a convenience wrapper around errors.As.

func Is

func Is(err, target error) bool

Is is a convenience wrapper around errors.Is.

func New

func New(msg string) error

New is a convenience wrapper around errors.New.

func Unwrap

func Unwrap(err error) error

Unwrap is a convenience wrapper around errors.Unwrap.

func Wrap

func Wrap(err error) error

Wrap wraps an error with the file and line where it was called.

Types

This section is empty.

Jump to

Keyboard shortcuts

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