wraperror

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2022 License: MIT Imports: 1 Imported by: 2

README

go-wraperror

license

WrapError is custom error struct implemented error interface and supporting errors.As, errors.Is, Unwrap ... and so on.

Getting Started

package main
import (
	"os"
	"errors"
	wraperror "github.com/gjbae1212/go-wraperror"
)


func main() {
	sample1 := errors.New("[err] tests")
	sample2 := &os.PathError{}
	sample3 := &os.SyscallError{}

	wrap := wraperror.Error(sample1)
	wrap = wrap.Wrap(sample2)

	// true
	errors.Is(wrap, sample1)
	errors.As(wrap, &sample1)
	// true
	errors.Is(wrap, sample2)
	errors.As(wrap, &sample2)
	// false
	errors.Is(wrap, sample3)
	errors.As(wrap, &sample3)
}

LICENSE

This project is following The MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type WrapError added in v0.7.0

type WrapError struct {
	// contains filtered or unexported fields
}

WrapError is custom error struct implemented error interface, supporting As, Is, Unwrap.

func Error

func Error(err error) *WrapError

Error converts error to WrapError.

func FromError added in v0.7.0

func FromError(err error) (*WrapError, bool)

FromError returns an error to WrapError, but if an error doesn't convert to WrapError, returning nil and false.

func (*WrapError) As added in v0.7.0

func (e *WrapError) As(target interface{}) bool

As Checks to equal e.child to err. It's implemented for errors package.

func (*WrapError) Child added in v0.7.0

func (e *WrapError) Child() error

Child returns child error.

func (*WrapError) Current added in v0.7.0

func (e *WrapError) Current() error

Current returns current error.

func (*WrapError) Error added in v0.7.0

func (e *WrapError) Error() string

Error returns a chained error string. It's implemented error interface.

func (*WrapError) Flatten added in v0.7.0

func (e *WrapError) Flatten() []error

Flatten returns an flatten error array.

func (*WrapError) Is added in v0.7.0

func (e *WrapError) Is(target error) bool

Is checks to equal e.current to err. It's implemented for errors package.

func (*WrapError) Unwrap added in v0.7.0

func (e *WrapError) Unwrap() error

Unwrap unwraps an error. It's implemented for errors package.

func (*WrapError) Wrap added in v0.7.0

func (e *WrapError) Wrap(err error) *WrapError

Wrap wraps an error.

Jump to

Keyboard shortcuts

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