Skip to content

cleanup: use %w instead of %v for error wrapping in fmt.Errorf - #1640

Open
safiya2610 wants to merge 2 commits into
volcano-sh:mainfrom
safiya2610:fix-error-wrapping
Open

cleanup: use %w instead of %v for error wrapping in fmt.Errorf#1640
safiya2610 wants to merge 2 commits into
volcano-sh:mainfrom
safiya2610:fix-error-wrapping

Conversation

@safiya2610

@safiya2610 safiya2610 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

I have done this using Ctrl+ shift+H, and perform replacement.

This PR systematically replaces fmt.Errorf("... %v", err) with fmt.Errorf("... %w", err) across the codebase. Using %w correctly wraps the error in Go 1.13+, preserving the original error type and allowing upstream functions to properly inspect it using errors.Is() and errors.As().
Fixes #1639

Signed-off-by: safiya2610 <lci2023053@iiitl.ac.in>
@LiZhenCheng9527

Copy link
Copy Markdown
Member

If you don't perform subsequent handling of the returned error using errors.Is() or errors.As(), I don't think it's necessary to make the change.

@kube-gopher

Copy link
Copy Markdown
Member

If you don't perform subsequent handling of the returned error using errors.Is() or errors.As(), I don't think it's necessary to make the change.

+1

@YaoZengzeng

Copy link
Copy Markdown
Member

How can we ensure that all future code consistently uses %w instead of %v?

Or we need to perform a periodic fix?

Signed-off-by: safiya2610 <lci2023053@iiitl.ac.in>
@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@safiya2610

Copy link
Copy Markdown
Contributor Author

How can we ensure that all future code consistently uses %w instead of %v?

Or we need to perform a periodic fix?

To ensure that all future code consistently uses %w instead of %v, I have enabled the errorlint linter in the .golangci.yaml file in my latest commit.
It will automatically fail the build if anyone tries to use %v for an error inside fmt.Errorf in the future..

@safiya2610

Copy link
Copy Markdown
Contributor Author

If you don't perform subsequent handling of the returned error using errors.Is() or errors.As(), I don't think it's necessary to make the change.

Even though errors.Is() and errors.As() are not currently used in these places, my intention was to preserve the original error so it can be handled properly if needed in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Accepted

Development

Successfully merging this pull request may close these issues.

Improper error wrapping: fmt.Errorf uses %v instead of %w across the codebase

5 participants