Skip to content

Commit

Permalink
updated the error string (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
g8rswimmer authored Aug 1, 2020
1 parent 44a316b commit 5720e71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package echain

import (
"errors"
"strings"
)

type link struct {
Expand All @@ -20,7 +21,13 @@ func New() *ErrorChain {
return &ErrorChain{}
}
func (e *ErrorChain) Error() string {
return e.head.err.Error()
errs := []string{}
h := e.head
for h != nil {
errs = append(errs, h.err.Error())
h = h.next
}
return strings.Join(errs, ": ")
}

// Unwrap will give the next error
Expand Down
2 changes: 1 addition & 1 deletion chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestErrorChain_Error(t *testing.T) {
},
},
},
want: "1",
want: "1: 2: 3",
},
}
for _, tt := range tests {
Expand Down

0 comments on commit 5720e71

Please sign in to comment.