From ad9ac08c1c6847630ddf6adbb32090af3b765398 Mon Sep 17 00:00:00 2001 From: Samuel K Date: Sat, 25 Apr 2026 14:36:48 -0500 Subject: [PATCH] fix(ux): use %w for proper error chain wrapping Replace %v with %w in fmt.Errorf calls so callers can use errors.Is/As to inspect underlying errors. Simplify redundant fmt.Errorf("%v", err) to return err directly. --- pkg/command/credential_supported.go | 6 +++--- pkg/survey/survey.go | 2 +- pkg/util/hash/hash.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/command/credential_supported.go b/pkg/command/credential_supported.go index b86c18aca..c973211a6 100644 --- a/pkg/command/credential_supported.go +++ b/pkg/command/credential_supported.go @@ -14,17 +14,17 @@ func ForUser(cmd *exec.Cmd, userName string) error { // Look up the user's UID and GID u, err := user.Lookup(userName) if err != nil { - return fmt.Errorf("failed to look up user %s: %v", userName, err) + return fmt.Errorf("failed to look up user %s: %w", userName, err) } uid, err := strconv.Atoi(u.Uid) if err != nil { - return fmt.Errorf("invalid UID %s: %v", u.Uid, err) + return fmt.Errorf("invalid UID %s: %w", u.Uid, err) } gid, err := strconv.Atoi(u.Gid) if err != nil { - return fmt.Errorf("invalid GID %s: %v", u.Gid, err) + return fmt.Errorf("invalid GID %s: %w", u.Gid, err) } // Set the user cmd should run as diff --git a/pkg/survey/survey.go b/pkg/survey/survey.go index 0577b3884..5868d73e3 100644 --- a/pkg/survey/survey.go +++ b/pkg/survey/survey.go @@ -122,7 +122,7 @@ func buildValidator(params *QuestionOptions, compiledRegex *regexp.Regexp) func( return errors.New(params.ValidationMessage) } - return fmt.Errorf("%v", err) + return err } } diff --git a/pkg/util/hash/hash.go b/pkg/util/hash/hash.go index 8660a1764..ccc5ce838 100644 --- a/pkg/util/hash/hash.go +++ b/pkg/util/hash/hash.go @@ -217,7 +217,7 @@ func (w *fileWalker) shouldSkipPath(relFilePath string) (bool, error) { skip, err := w.pm.MatchesOrParentMatches(relFilePath) if err != nil { - return false, fmt.Errorf("failed to match %s: %v", relFilePath, err) + return false, fmt.Errorf("failed to match %s: %w", relFilePath, err) } return skip, nil