Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
Add square brackets around error string for Errors (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
xichen2020 authored Feb 13, 2017
1 parent 02e9797 commit 3a8328d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ type Errors []error
// Error implements error.
func (e Errors) Error() string {
buf := bytes.NewBuffer(nil)
buf.WriteString("[")
for i, err := range e {
if err == nil {
buf.WriteString("<nil>")
Expand All @@ -260,5 +261,6 @@ func (e Errors) Error() string {
buf.WriteString(", ")
}
}
buf.WriteString("]")
return buf.String()
}
4 changes: 2 additions & 2 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ func TestErrorsIsAnErrorAndFormatsErrors(t *testing.T) {
fmt.Errorf("some error: foo=2, bar=baz"),
fmt.Errorf("some other error: foo=42, bar=qux"),
})
assert.Equal(t, "<some error: foo=2, bar=baz>, "+
"<some other error: foo=42, bar=qux>", errs.Error())
assert.Equal(t, "[<some error: foo=2, bar=baz>, "+
"<some other error: foo=42, bar=qux>]", errs.Error())
}

0 comments on commit 3a8328d

Please sign in to comment.