go-errors – github.com/grufwub/go-errors Index | Files

package errors

import "github.com/grufwub/go-errors"

Index

Functions

func Is

func Is(err, target error) bool

Is wraps "errors".Is()

Types

type BaseError

type BaseError string

BaseError is an error type that supports being defined as `const`, as it is simply a string typedef

func BaseErrorf

func BaseErrorf(s string, a ...interface{}) BaseError

BaseErrorf returns a new BaseError based on the supplied format string

func (BaseError) Error

func (e BaseError) Error() string

func (BaseError) Extend

func (e BaseError) Extend(a ...interface{}) Error

func (BaseError) Extendf

func (e BaseError) Extendf(s string, a ...interface{}) Error

func (BaseError) Is

func (e BaseError) Is(target error) bool

func (BaseError) Original

func (e BaseError) Original() error

func (BaseError) Unwrap

func (e BaseError) Unwrap() error

func (BaseError) Wrap

func (e BaseError) Wrap(err error) Error

func (BaseError) WrapWithin

func (e BaseError) WrapWithin(err error) Error

type Error

type Error interface {
	// Error returns the error string
	Error() string

	// Is returns whether an error is of type [supplied target]
	Is(error) bool

	// Original returns the original error, i.e. without any of our wrappers
	// providing extra methods
	//
	// e.g.
	// er := errors.With(library.ErrSomeIssue).Extend("more text!")
	// og := er.Original()
	//
	// switch library.ErrSomeIssue {
	// case er:
	//     // we will never reach here
	// case og:
	//     // this is the original error!
	// }
	Original() error

	// Unwrap attempts to unwrap any internally wrapped errors
	//
	// e.g.
	// err1 := errors.BaseError("bad error oh noes")
	// err2 := err1.WrapWithin(library.ErrSomeIssue)
	//
	// if err2.Unwrap() == err1 {
	//     // this is true!
	// }
	Unwrap() error

	// Extend extends an error with extra information
	Extend(...interface{}) Error

	// Extendf extends an error with extra information using format strings
	Extendf(string, ...interface{}) Error

	// Wrap wraps the current error within a wrapper, using the originating
	// error-in-wrapper as the outer error
	Wrap(error) Error

	// WrapWithin wraps the originating error within a wrapper, using the
	// supplied error-in-wrapper as the outer error
	WrapWithin(error) Error
}

Error defines an error interface with helper functions for extending with extra information, wrapping within errors, and .Is() .Unwrap() to support standard "errors" library utilities.

func With

func With(err error) Error

With wraps a non errors.Error type error within an errors.Error interface

Source Files

errors.go

Version
v0.3.4 (latest)
Published
Feb 21, 2021
Platform
linux/amd64
Imports
2 packages
Last checked
1 month ago

Tools for package owners.