Skip to content

Commit 6b3a30e

Browse files
authored
🐛 [commonerrors] Ensure the wrapping of an already wrapped error does not result in message duplication (#707)
<!-- Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved. SPDX-License-Identifier: Apache-2.0 --> ### Description <!-- Please add any detail or context that would be useful to a reviewer. --> - fix error message for wrapped errors ### Test Coverage <!-- Please put an `x` in the correct box e.g. `[x]` to indicate the testing coverage of this change. --> - [x] This change is covered by existing or additional automated tests. - [ ] Manual testing has been performed (and evidence provided) as automated testing was not feasible. - [ ] Additional tests are not required for this change (e.g. documentation update).
1 parent 47677cb commit 6b3a30e

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

changes/20250911133122.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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`

utils/commonerrors/errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ func WrapError(targetError, originalError error, msg string) error {
389389
} else {
390390
cleansedMsg := strings.TrimSpace(msg)
391391
if cleansedMsg == "" {
392+
if Any(tErr, originalError) {
393+
// The error is already wrapped and of the same type.
394+
return originalError
395+
}
392396
return New(tErr, originalError.Error())
393397
} else {
394398
return Errorf(

utils/commonerrors/errors_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,5 @@ func TestString(t *testing.T) {
272272
assert.Equal(t, "unsupported: not found", WrapError(ErrUnsupported, ErrNotFound, "").Error())
273273
assert.Equal(t, "unknown: test: unsupported", WrapError(nil, ErrUnsupported, "test").Error())
274274
assert.Equal(t, "unsupported: test 56: not found", WrapErrorf(ErrUnsupported, ErrNotFound, "test %v", 56).Error())
275+
assert.Equal(t, "unsupported: test", WrapError(ErrUnsupported, Newf(ErrUnsupported, "test"), "").Error())
275276
}

0 commit comments

Comments
 (0)