Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MError ¶
type MError struct {
// contains filtered or unexported fields
}
MError is an error that able to store multiple errors.
func ErrorFrom ¶
ErrorFrom creates an MError err from passed original error and it's inner errs.
err's msg will be the same as original.Error(). Function call errors.Is(err, original) will return true.
If passed original is already an MError, then original is returned.
Example ¶
package main
import (
"errors"
"fmt"
"github.com/k1gabyt0/erry"
)
func main() {
errA := errors.New("err A")
errB := errors.New("err B")
errC := errors.New("err C")
multierr := erry.ErrorFrom(errA).Wrap(errB, errC)
// msg: errA.Error()
// original: errA
// / \
// errB errC
fmt.Println(multierr)
if errors.Is(multierr, errA) {
fmt.Println("This is error A")
}
if errors.Is(multierr, errB) {
fmt.Println("This is error B")
}
if errors.Is(multierr, errB) {
fmt.Println("This is error C")
}
}
Output: err A: err B err C This is error A This is error B This is error C
func NewError ¶
NewError returns MError with passed msg and errs.
Passed nil errs though will be filtered. Only non-nil errs are stored.
Example ¶
package main
import (
"errors"
"fmt"
"github.com/k1gabyt0/erry"
)
func main() {
errA := errors.New("err A")
errB := errors.New("err B")
multierr := erry.NewError("multierror", errA, errB)
// also this below is the same
// multierr = erry.NewError("multierror").Wrap(errA, errB)
// msg="multierror"
// / \
// errA errB
fmt.Println(multierr)
if errors.Is(multierr, errA) {
fmt.Println("This is error A")
}
if errors.Is(multierr, errB) {
fmt.Println("This is error B")
}
}
Output: multierror: err A err B This is error A This is error B
func (*MError) As ¶
As finds the first error in v's tree that matches target(starting with the root), and if one is found, sets target to that error value and returns true. Otherwise, it returns false.
As finds the first matching error in a preorder traversal of the tree.
func (*MError) Is ¶
Is reports whether any error in v's tree matches target.
It is always returns true if checked against non-nil original.