import (
"errors"
- "fmt"
)
type Error struct {
return false
}
+// Grow will overwrite reason but save action for catch
func Grow(e error, son Error) Error {
if v, ok := e.(Error); ok {
son.son = v
var (
ErrSimplifyFunc = func(e error) string {
- if es := e.Error(); len(es) > 20 {
- return fmt.Sprintf("%.16s...\n", es)
- } else {
- return es + "\n"
- }
+ return e.Error() + "\n"
+ }
+ ErrInLineFunc = func(e error) string {
+ return " > " + e.Error()
}
)
}
}
+func Test2(t *testing.T) {
+ e := Join(New("r0", "a0"), New("r1", "a1"))
+ t.Log(ErrorFormat(e, ErrSimplifyFunc))
+ t.Log(ErrorFormat(e, ErrInLineFunc))
+ if ErrorFormat(e, ErrSimplifyFunc) != "r0\nr1\n" {
+ t.FailNow()
+ }
+ if ErrorFormat(e, ErrInLineFunc) != " > r0 > r1" {
+ t.FailNow()
+ }
+}
+
func Test1(t *testing.T) {
e := Join(io.EOF, io.ErrClosedPipe)
e = Join(io.EOF, e)
if !errors.Is(e, io.ErrClosedPipe) {
t.FailNow()
}
- if ErrorFormat(e, ErrSimplifyFunc) != "EOF\nEOF\nio: read/write o...\n" {
+ if ErrorFormat(e, ErrSimplifyFunc) != "EOF\nEOF\nio: read/write on closed pipe\n" {
+ t.FailNow()
+ }
+ if ErrorFormat(e, ErrInLineFunc) != " > EOF > EOF > io: read/write on closed pipe" {
t.FailNow()
}
}