Documentation ¶
Overview ¶
Package errval is error value generation helper.
Example ¶
package main import ( "fmt" "os" "github.com/KoharaKazuya/errval" "golang.org/x/xerrors" ) // error types definition var ( ErrInvalid = errval.Type("invalid argument") ErrPermission = errval.Type("permission denied") ) func main() { err1 := doSomething1() if xerrors.Is(err1, ErrInvalid) { fmt.Println("doSomething1 returns an ErrInvalid error") } err2 := doSomething2() if xerrors.Is(err2, ErrPermission) { fmt.Println("doSomething2 returns an ErrPermission error") } } func doSomething1() error { return ErrInvalid.New() // generate error } func doSomething2() error { _, err := os.Open("/tmp/hogehoge") // ErrNotExist if err != nil { return ErrPermission.Wrap(err) // generate wrapped error } return nil }
Output: doSomething1 returns an ErrInvalid error doSomething2 returns an ErrPermission error
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrType ¶
type ErrType struct {
// contains filtered or unexported fields
}
ErrType presents an error type.
type ErrVal ¶
type ErrVal struct {
// contains filtered or unexported fields
}
ErrVal presents an error value. ErrVal must be created as return value of `ErrType.New` or `ErrType.Wrap`.
func (*ErrVal) FormatError ¶
FormatError prints the stack as error detail.
Click to show internal directories.
Click to hide internal directories.