Skip to content

Commit

Permalink
fix(api): wrapping a multi error should not reset 'from' infos (#5387)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Aug 21, 2020
1 parent e2bee0a commit df87b6f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sdk/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,10 +808,20 @@ func WrapError(err error, format string, args ...interface{}) error {
}
}

httpError := ErrUnknownError

if e, ok := err.(*MultiError); ok {
var ss []string
for i := range *e {
ss = append(ss, ExtractHTTPError((*e)[i], "").printLight())
}
httpError.From = strings.Join(ss, ", ")
}

return errorWithStack{
root: errors.Wrap(err, m),
stack: callers(),
httpError: ErrUnknownError,
httpError: httpError,
}
}

Expand Down
5 changes: 5 additions & 0 deletions sdk/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ func TestMultiError(t *testing.T) {
assert.Equal(t, "TestMultiError: internal server error (from: internal server error, wrong request: my second error, internal server error, already exists: my fourth error) (caused by: TestMultiError: internal server error (caused by: my first error), TestMultiError: wrong request (from: my second error), TestMultiError: internal server error (caused by: hidden info: my third error), TestMultiError: already exists (from: my fourth error))", stackErr.Error())
httpErr = ExtractHTTPError(stackErr, "fr")
assert.Equal(t, "erreur interne (from: internal server error, wrong request: my second error, internal server error, already exists: my fourth error)", httpErr.Error())

stackErr = WrapError(mError, "more info")
assert.Equal(t, "TestMultiError: internal server error (from: internal server error, wrong request: my second error, internal server error, already exists: my fourth error) (caused by: more info: TestMultiError: internal server error (caused by: my first error), TestMultiError: wrong request (from: my second error), TestMultiError: internal server error (caused by: hidden info: my third error), TestMultiError: already exists (from: my fourth error))", stackErr.Error())
httpErr = ExtractHTTPError(stackErr, "fr")
assert.Equal(t, "erreur interne (from: internal server error, wrong request: my second error, internal server error, already exists: my fourth error)", httpErr.Error())
}

func Test_cause(t *testing.T) {
Expand Down

0 comments on commit df87b6f

Please sign in to comment.