deps: remove xerrors in favor of stdlib fmt/errors#2465
Open
deps: remove xerrors in favor of stdlib fmt/errors#2465
Conversation
Replace all 788 usages of golang.org/x/xerrors across 72 files with stdlib equivalents: xerrors.Errorf → fmt.Errorf, xerrors.New → errors.New. For []error slices previously passed to xerrors.Errorf with %w, use errors.Join() to properly wrap multiple errors. Fix pre-existing bug in detector/vuls2/db.go where session.SchemaVersion (a function) was passed to %d format verb instead of the result variable sv. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why (motivation for removing this dependency)
golang.org/x/xerrorswas the error handling library used before Go 1.13 added%wwrapping tofmt.Errorfanderrors.Is/errors.Asto the stdlibWhat (replacement details)
xerrors.Errorf→fmt.Errorf,xerrors.New→errors.New[]errorwrapping fix: 8 call sites passed[]errorslices to%w(which xerrors silently accepted). These now useerrors.Join(errs...)for proper multi-error wrappingdetector/vuls2/db.gopassedsession.SchemaVersion(a function value) to%dformat verb — fixed to use the result variablesverrors.New/fmt.Errorfstrings that were capitalized or ended with punctuation — lowercased to satisfyrevivelinter (xerrors was exempt from this rule)Changed files (72 .go files + go.mod)
config/,detector/,scanner/,reporter/,gost/, etc.xerrors.Errorf→fmt.Errorf,xerrors.New→errors.New, import cleanupdetector/kevuln.go,detector/msf.go,detector/cti.go,detector/cve_client.go,detector/exploitdb.go,gost/util.go,scanner/debian.go%wwith[]error→errors.Join(errs...)scanner/redhatbase.go,scanner/suse.go%wwith non-errorexecResult→%vdetector/vuls2/db.gosession.SchemaVersion(func) →sv(int) in format stringconfig/portscan.go,scanner/base.gogo.modxerrorsdemoted from direct to indirectSafety (why this is safe)
fmt.Errorfwith%wis the official stdlib replacement forxerrors.Errorfsince Go 1.13errors.Newis the direct stdlib equivalent ofxerrors.Newerrors.Joinproperly wraps[]errorslices (improvement over xerrors which silently stringified them)xerrors.Is,xerrors.As,xerrors.Formatter,xerrors.Frame)Test plan
go build ./cmd/...— passgo test ./...— 15 packages passGOEXPERIMENT=jsonv2 golangci-lint run ./...— 0 issuesReview hint (how to review efficiently)
go.mod— confirms xerrors moved to indirectdetector/detector.go,scanner/base.go) — verify the mechanical pattern is consistentdetector/vuls2/db.go(bug fix), the 7errors.Joincall sites, andconfig/portscan.go(lowercased error strings)xerrors.Xxx→fmt/errors.Xxxwith no logic changes🤖 Generated with Claude Code