errors

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2023 License: MIT Imports: 1 Imported by: 7

README

Slightly better errors package

Just so you don't have to construct a holding variable separately and can write just this:

if err, ok := errors.As[*someError](err); ok {
  // ...
}

Documentation

Overview

Package errors is a wrapper for `errors` package from standard library that takes advantage of recently introduced generics.

Function As is replaced to allow the following:

if err, ok := errors.As[*someError](err); ok {
  ...
}

Rest of the standard `errors` package is re-exported as is.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupported = errors.ErrUnsupported
	Is             = errors.Is
	Join           = errors.Join
	New            = errors.New
	Unwrap         = errors.Unwrap
)

Functions

func As

func As[T any](err error) (T, bool)

As works just like `errors.As`, but it takes care of boilerplate for you.

Instead of:

var myErr *someError
if errors.As(err, &myErr) {
   ...
}

you can write this:

if err, ok := errors.As[*someError](err); ok {
  ...
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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