From 6ff409ca763b46ab18689417811a7fdc05c928c4 Mon Sep 17 00:00:00 2001 From: Adrien CABARBAYE Date: Thu, 11 Sep 2025 13:31:38 +0100 Subject: [PATCH] :bug: `[commonerrors]` Ensure the wrapping of an already wrapped error does not result in message duplication --- changes/20250911133122.bugfix | 1 + utils/commonerrors/errors.go | 4 ++++ utils/commonerrors/errors_test.go | 1 + 3 files changed, 6 insertions(+) create mode 100644 changes/20250911133122.bugfix diff --git a/changes/20250911133122.bugfix b/changes/20250911133122.bugfix new file mode 100644 index 0000000000..e0637b20d5 --- /dev/null +++ b/changes/20250911133122.bugfix @@ -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` diff --git a/utils/commonerrors/errors.go b/utils/commonerrors/errors.go index 3e1fa74af8..beee3f27f7 100644 --- a/utils/commonerrors/errors.go +++ b/utils/commonerrors/errors.go @@ -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( diff --git a/utils/commonerrors/errors_test.go b/utils/commonerrors/errors_test.go index 9511986533..e0d231269a 100644 --- a/utils/commonerrors/errors_test.go +++ b/utils/commonerrors/errors_test.go @@ -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()) }