wraperr

package
v0.5.7 Latest Latest
Warning

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

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

Documentation

Overview

Package wraperr packages an error with another wrapped error This allows errors.Is to work without directly injecting the string of the wrapped error

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WrapErr

type WrapErr struct {
	Err  error
	Wrap error
}

WrapErr wraps an underlying error with another error

Example usage:

var ErrLimit = errors.New("Limit reached")
...
func someFunc() error {
  return wrapper.WrapErr{Err: fmt.Errorf("Limit %d reached on %s", limit, instance), Wrap: ErrLimit}
}
...
if errors.Is(err, ErrLimit) { ... }

This makes it easier to include a custom error message while also allowing

func New

func New(err, wrap error) WrapErr

New returns a new WrapErr

func (WrapErr) Error

func (e WrapErr) Error() string

func (WrapErr) Unwrap

func (e WrapErr) Unwrap() error

Jump to

Keyboard shortcuts

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