gjbae1212 / go-wraperror

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

About

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

License:MIT License


Languages

Language:Go 98.7%Language:Shell 1.3%