From 4f6549fc437cba8a708099bac23dc7f99e9b0606 Mon Sep 17 00:00:00 2001 From: basgys Date: Thu, 3 Sep 2026 18:24:30 +0200 Subject: [PATCH] fix: keep the wrapped cause in NotFound and PermissionDenied messages MissingFailure.Error and PermissionFailure.Error returned a bare constant and discarded the error they wrap, so WithNotFound(err) rendered as "resource not found" no matter what err said. Route both through maybeWrap, as the other failure types already do. The singletons wrap nil, so their messages are unchanged. --- faults.go | 4 ++-- faults_test.go | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/faults.go b/faults.go index 1c3fb5e..ff8d6f3 100644 --- a/faults.go +++ b/faults.go @@ -491,7 +491,7 @@ type MissingFailure struct { } func (e *MissingFailure) Error() string { - return "resource not found" + return maybeWrap(e.error, "resource not found").Error() } func (e *MissingFailure) Is(target error) bool { @@ -508,7 +508,7 @@ type PermissionFailure struct { } func (e *PermissionFailure) Error() string { - return "permission denied" + return maybeWrap(e.error, "permission denied").Error() } func (e *PermissionFailure) Is(target error) bool { diff --git a/faults_test.go b/faults_test.go index 3b74e19..431dc30 100644 --- a/faults_test.go +++ b/faults_test.go @@ -508,6 +508,16 @@ func TestErrorMessage(t *testing.T) { err: faults.WithResourceExhausted(cause), wantMsg: "quota failure: underlying issue", }, + { + scenario: "WithNotFound wrapping a cause includes the cause in the message", + err: faults.WithNotFound(cause), + wantMsg: "resource not found: underlying issue", + }, + { + scenario: "WithPermissionDenied wrapping a cause includes the cause in the message", + err: faults.WithPermissionDenied(cause), + wantMsg: "permission denied: underlying issue", + }, } for _, tt := range tests {