return false
}
-// Grow will append error action for catch
+// Grow will append e to fe
func Grow(fe Error, e error) Error {
if v, ok := e.(Error); ok {
fe.son = v
return fe
}
-func New(action string, reason ...string) (e Error) {
+func New(reason string, action ...string) (e Error) {
e = Error{
- action: action,
+ Reason: reason,
}
- if len(reason) > 0 {
- e.Reason = reason[0]
+ if len(action) > 0 {
+ e.action = action[0]
}
return
}
type ErrFormat func(e error) string
var (
- ErrSimplifyFunc = func(e error) string {
+ ErrSimplifyFunc ErrFormat = func(e error) string {
return e.Error() + "\n"
}
- ErrActionSimplifyFunc = func(e error) string {
+ ErrActionSimplifyFunc ErrFormat = func(e error) string {
if err, ok := e.(Error); ok {
return err.action + ":" + e.Error() + "\n"
} else {
return e.Error() + "\n"
}
}
- ErrInLineFunc = func(e error) string {
+ ErrInLineFunc ErrFormat = func(e error) string {
return "> " + e.Error() + " "
}
- ErrActionInLineFunc = func(e error) string {
+ ErrActionInLineFunc ErrFormat = func(e error) string {
if err, ok := e.(Error); ok {
return "> " + err.action + ":" + e.Error() + " "
} else {
err = New("r0", "a0")
- if !Catch(err, "r0") {
+ if !Catch(err, "a0") {
t.Fail()
}
- if Catch(err, "r1") {
+ if Catch(err, "r0") {
t.Fail()
}
err = Grow(New("r1", "a1"), err)
- if !Catch(err, "r0") {
+ if !Catch(err, "a1") {
t.Fail()
}
- if !Catch(err, "r1") {
+ if !Catch(err, "a0") {
t.Fail()
}
}
+
func TestXxx2(t *testing.T) {
err := Grow(New("r1", "a1"), io.EOF)
- if !Catch(err, "r1") {
+ if !Catch(err, "a1") {
t.Fatal()
}
t.Log(err.Error())
t.Log(ErrorFormat(e))
t.Log(ErrorFormat(e, ErrSimplifyFunc))
t.Log(ErrorFormat(e, ErrInLineFunc))
- if ErrorFormat(e, ErrSimplifyFunc) != "a0\na1\n" {
+ if ErrorFormat(e, ErrSimplifyFunc) != "r0\nr1\n" {
t.FailNow()
}
- if ErrorFormat(e, ErrInLineFunc) != "> a0 > a1 " {
+ if ErrorFormat(e, ErrInLineFunc) != "> r0 > r1 " {
t.FailNow()
}
}
func Test3(t *testing.T) {
e := New("1")
- if e.Error() != "" {
- t.FailNow()
+ if e.Error() != "1" {
+ t.Fatal()
}
e1 := e.WithReason("2")
- if e.Error() != "" {
- t.FailNow()
+ if e.Error() != "1" {
+ t.Fatal()
}
if e1.Error() != "2" {
- t.FailNow()
+ t.Fatal()
}
}