8000 plumbing: use errors package for comparison by PascalBourdier · Pull Request #1469 · go-git/go-git · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

plumbing: use errors package for comparison #1469

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: previous-main
Choose a base branch
from

Conversation

PascalBourdier
Copy link
Contributor

Comparison with errors using equality operators fails on wrapped errors

use the golang 1.13 best practices: https://tip.golang.org/doc/go1.13#error_wrapping

@Copilot Copilot AI review requested due to automatic review settings March 24, 2025 10:19
Copy link
Contributor
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors error handling across the codebase to follow Go 1.13 best practices by replacing direct error equality checks with errors.Is and errors.As.

  • Replace error equality comparisons with errors.Is and errors.As.
  • Update multiple files to import the "errors" package and adjust error handling accordingly.
  • Ensure consistency in error handling across both core and example packages.

Reviewed Changes

Copilot reviewed 44 out of 44 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cli/go-git/main.go Refactored error handling using errors.As and errors.Is for flag errors.
plumbing/object/commit_walker_limit.go Updated error comparisons for storer.ErrStop using errors.Is.
plumbing/object/commit_walker.go Refactored error comparisons for storer.ErrStop and plumbing.ErrReferenceNotFound.
plumbing/object/commit_walker_bfs.go Updated error comparisons for storer.ErrStop in ForEach.
plumbing/object/commitgraph/commitnode_walker_ctime.go Updated error comparisons for storer.ErrStop in ForEach.
plumbing/object/commit_walker_ctime.go Updated error comparisons for storer.ErrStop using errors.Is.
plumbing/object/commit_walker_path.go Updated error comparisons for storer.ErrStop using errors.Is.
plumbing/object/commitgraph/commitnode_walker_topo_order.go Updated error comparisons for storer.ErrStop using errors.Is.
plumbing/object/file.go Updated error comparisons for storer.ErrStop in FileIter using errors.Is.
options.go Updated error comparisons for plumbing.ErrReferenceNotFound using errors.Is.
config/config.go Updated error comparisons for ErrModuleBadPath using errors.Is.
plumbing/object/commitgraph/commitnode.go Updated error comparisons for ParentNode errors using errors.Is.
_examples/checkout-branch/main.go Updated error comparisons for git.NoErrAlreadyUpToDate using errors.Is.
_examples/tag-create-push/main.go Updated error comparisons for git.NoErrAlreadyUpToDate using errors.Is.
_examples/ls/main.go Updated error comparisons for object.ErrDirectoryNotFound using errors.Is.
plumbing/object/difftree.go Updated error comparisons for merkletrie.ErrCanceled using errors.Is.
plumbing/format/pktline/pktline.go Updated error comparisons for io.ErrUnexpectedEOF using errors.Is.
Comments suppressed due to low confidence (1)

cli/go-git/main.go:34

  • e.Type is likely a simple value (e.g. an enum or integer) rather than an error, so using errors.Is on e.Type is inappropriate. Consider reverting to a direct equality check (e.g. e.Type == flags.ErrCommandRequired) for accurate comparison.
if errors.As(err, &e) && errors.Is(e.Type, flags.ErrCommandRequired) {

@PascalBourdier PascalBourdier changed the title fix: use "errors" package for comparaison use "errors" package for comparaison Mar 24, 2025
@PascalBourdier PascalBourdier changed the title use "errors" package for comparaison plumbing: use "errors" package for comparaison Mar 26, 2025
@PascalBourdier PascalBourdier changed the title plumbing: use "errors" package for comparaison plumbing: use errors package for comparaison Mar 26, 2025
Comparison with errors using equality operators fails on wrapped errors

use the golang 1.13 best practices: https://tip.golang.org/doc/go1.13#error_wrapping
@PascalBourdier PascalBourdier changed the title plumbing: use errors package for comparaison plumbing: use errors package for comparison Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0