This commit is contained in:
Albin Kerouanton 2024-04-16 15:57:47 +02:00 committed by GitHub
commit f36cde3db2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View file

@ -31,9 +31,6 @@ type joinError struct {
}
func (e *joinError) Error() string {
if len(e.errs) == 1 {
return strings.TrimSpace(e.errs[0].Error())
}
stringErrs := make([]string, 0, len(e.errs))
for _, subErr := range e.errs {
stringErrs = append(stringErrs, strings.Replace(subErr.Error(), "\n", "\n\t", -1))

View file

@ -10,10 +10,12 @@ import (
func TestErrorJoin(t *testing.T) {
t.Run("single", func(t *testing.T) {
err := Join(fmt.Errorf("invalid config: %w", Join(errors.New("foo"))))
const expected = `invalid config: foo`
err := fmt.Errorf("invalid config:\n%w", Join(errors.New("foo")))
const expected = `invalid config:
* foo`
assert.Equal(t, err.Error(), expected)
})
t.Run("multiple", func(t *testing.T) {
err := Join(errors.New("foobar"), fmt.Errorf("invalid config: \n%w", Join(errors.New("foo"), errors.New("bar"))))
const expected = `* foobar