Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/20250911133122.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:bug: `[commonerrors]` Ensure the wrapping of an already wrapped error does not result in message duplication such as `unknown: unknown: blah` or `unexpected: unexpected: blah`
4 changes: 4 additions & 0 deletions utils/commonerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ func WrapError(targetError, originalError error, msg string) error {
} else {
cleansedMsg := strings.TrimSpace(msg)
if cleansedMsg == "" {
if Any(tErr, originalError) {
// The error is already wrapped and of the same type.
return originalError
}
return New(tErr, originalError.Error())
} else {
return Errorf(
Expand Down
1 change: 1 addition & 0 deletions utils/commonerrors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,5 @@ func TestString(t *testing.T) {
assert.Equal(t, "unsupported: not found", WrapError(ErrUnsupported, ErrNotFound, "").Error())
assert.Equal(t, "unknown: test: unsupported", WrapError(nil, ErrUnsupported, "test").Error())
assert.Equal(t, "unsupported: test 56: not found", WrapErrorf(ErrUnsupported, ErrNotFound, "test %v", 56).Error())
assert.Equal(t, "unsupported: test", WrapError(ErrUnsupported, Newf(ErrUnsupported, "test"), "").Error())
}
Loading