Skip to content
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

Error inconsistencies #1059

Open
akamensky opened this issue Mar 18, 2024 · 0 comments
Open

Error inconsistencies #1059

akamensky opened this issue Mar 18, 2024 · 0 comments

Comments

@akamensky
Copy link

akamensky commented Mar 18, 2024

There are too many errors for "Not found".

In my code to just be able to check if something is "not found" I have to do:

func IsNotFound(err error) bool {
	switch {
	case errors.Is(err, git.ErrBranchNotFound):
		return true
	case errors.Is(err, object.ErrDirectoryNotFound):
		return true
	case errors.Is(err, object.ErrEntryNotFound):
		return true
	case errors.Is(err, object.ErrFileNotFound):
		return true
	case errors.Is(err, object.ErrParentNotFound):
		return true
	case errors.Is(err, plumbing.ErrReferenceNotFound):
		return true
	case errors.Is(err, plumbing.ErrObjectNotFound):
		return true
	default:
		return false
	}
}

Now I stumbled on the fact that if I do clone over http, I get plumbing.ErrReferenceNotFound which is an error type and can be used with errors.Is().

But if i clone over ssh, i get git.NoMatchingRefSpecError, which is NOT an error type (it is a struct that implements error). For this one I have to add case git.NoMatchingRefSpecError{}.Is(err): return true to make it work.

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

No branches or pull requests

1 participant