errors icon indicating copy to clipboard operation
errors copied to clipboard

Error details that created with `errors.NewWithDetails` are lost after it combined using `errors.Combine`

Open dimasdanz opened this issue 3 years ago • 1 comments

Code to reproduce

errWithDetail := errors.NewWithDetails(
 "errorMessage",
  "key", "value",
)
errOther := errors.New("Something")

errors.GetDetails(errWithDetail) // [key, value] -> detail exists
errors.GetDetails(errors.Combine(errWithDetail, errOther) // [] -> prints empty slice

// also happened here
errors.Append(errWithDetail, errOther) // []

Is this expected?

dimasdanz avatar Jan 26 '22 13:01 dimasdanz

Good question...I'd say yeah, this makes sense. Not returning details is somewhat easier than resolving potentially conflicting ones.

Also, returning multiple errors should be relatively rare, so in those cases you might want to unpack errors and handle them separately. If you use an error handler, you could actually implement a middleware that unpacks these errors for you and passes them to the underlying handler one by one.

sagikazarmark avatar Jan 26 '22 13:01 sagikazarmark