From 5720e710ebcc9e1a6af474669be6db84c249cbf9 Mon Sep 17 00:00:00 2001 From: g8rswimmer <34941871+g8rswimmer@users.noreply.github.com> Date: Fri, 31 Jul 2020 17:04:15 -0700 Subject: [PATCH] updated the error string (#3) --- chain.go | 9 ++++++++- chain_test.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/chain.go b/chain.go index 66bcc93..d55c01a 100644 --- a/chain.go +++ b/chain.go @@ -2,6 +2,7 @@ package echain import ( "errors" + "strings" ) type link struct { @@ -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 diff --git a/chain_test.go b/chain_test.go index 3b55258..4f0d24a 100644 --- a/chain_test.go +++ b/chain_test.go @@ -125,7 +125,7 @@ func TestErrorChain_Error(t *testing.T) { }, }, }, - want: "1", + want: "1: 2: 3", }, } for _, tt := range tests {