From 89dd71b6d77e63a5430e68d8e10506a8dec86e63 Mon Sep 17 00:00:00 2001 From: chainchad <96362174+chainchad@users.noreply.github.com> Date: Fri, 6 Dec 2024 19:09:28 -0500 Subject: [PATCH] Appease linter --- .../internal/updater/updater.go | 18 +++++++++--------- .../internal/updater/updater_test.go | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tools/gomod-local-update/internal/updater/updater.go b/tools/gomod-local-update/internal/updater/updater.go index d44e144192f..44c99fb273c 100644 --- a/tools/gomod-local-update/internal/updater/updater.go +++ b/tools/gomod-local-update/internal/updater/updater.go @@ -81,7 +81,7 @@ func (u *Updater) getGitInfo(remote, branch string) (string, time.Time, error) { // Use u.git.Command for ls-remote out, err := u.git.Command(ctx, "ls-remote", remote, "refs/heads/"+branch) if err != nil { - return "", time.Time{}, fmt.Errorf("%w: failed to fetch commit SHA from %s/%s: %v", + return "", time.Time{}, fmt.Errorf("%w: failed to fetch commit SHA from %s/%s: %w", ErrModOperation, remote, branch, err) } if len(out) == 0 { @@ -98,14 +98,14 @@ func (u *Updater) getGitInfo(remote, branch string) (string, time.Time, error) { } // Use u.git.Command for show - out, err = u.git.Command(ctx, "show", "-s", "--format=%cI", sha) - if err != nil { - return "", time.Time{}, fmt.Errorf("failed to get commit time: %w", err) + showOut, showErr := u.git.Command(ctx, "show", "-s", "--format=%cI", sha) + if showErr != nil { + return "", time.Time{}, fmt.Errorf("failed to get commit time: %w", showErr) } - commitTime, err := time.Parse(gitTimeFormat, strings.TrimSpace(string(out))) - if err != nil { - return "", time.Time{}, fmt.Errorf("failed to parse commit time: %w", err) + commitTime, parseErr := time.Parse(gitTimeFormat, strings.TrimSpace(string(showOut))) + if parseErr != nil { + return "", time.Time{}, fmt.Errorf("failed to parse commit time: %w", parseErr) } return sha[:gitSHALength], commitTime, nil @@ -227,12 +227,12 @@ func isLocalPath(path string) bool { func (u *Updater) readModFile() (*modfile.File, error) { content, err := u.system.ReadFile(goModFile) if err != nil { - return nil, fmt.Errorf("%w: unable to read go.mod: %v", ErrModOperation, err) + return nil, fmt.Errorf("unable to read go.mod: %w", err) } modFile, err := modfile.Parse(goModFile, content, nil) if err != nil { - return nil, fmt.Errorf("%w: invalid go.mod format: %v", ErrModOperation, err) + return nil, fmt.Errorf("%w: invalid go.mod format: %w", ErrModOperation, err) // Changed %v to %w } return modFile, nil diff --git a/tools/gomod-local-update/internal/updater/updater_test.go b/tools/gomod-local-update/internal/updater/updater_test.go index da1af2f97e0..a08e17ddd7e 100644 --- a/tools/gomod-local-update/internal/updater/updater_test.go +++ b/tools/gomod-local-update/internal/updater/updater_test.go @@ -24,7 +24,7 @@ func (m *mockGitExecutor) Command(ctx context.Context, args ...string) ([]byte, } remote := args[1] if remote == "invalid*remote" { - return nil, fmt.Errorf("%w: git remote '%s' contains invalid characters", ErrInvalidConfig, remote) + return nil, fmt.Errorf("%w: git remote '%s' contains invalid characters", ErrInvalidConfig, remote) // Fixed: added %w } // Return a full 40-character SHA fullSHA := fmt.Sprintf("%s%s", m.sha, strings.Repeat("0", 40-len(m.sha)))