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

git-ext: Better handling of "not found" errors #29

Open
cloudhead opened this issue Oct 10, 2022 · 5 comments
Open

git-ext: Better handling of "not found" errors #29

cloudhead opened this issue Oct 10, 2022 · 5 comments

Comments

@cloudhead
Copy link
Contributor

Currently I have code like this:

        match repo.reference(remote, sigref) {
            Err(git_ext::Error::Git(e)) if git_ext::is_not_found_err(&e) => None,
            Err(git_ext::Error::NotFound(_)) => None,
            Err(e) => return Err(e.into()),
...
        };

It would be nice if git_ext::Error simply had a is_not_found(&self) -> bool method, so that it could be converted to:

        match repo.reference(remote, sigref) {
            Err(e) if e.is_not_found() => None,
            Err(e) => return Err(e.into()),
...
        };

This is the pattern I've been using with my other error types.

@FintanH
Copy link
Collaborator

FintanH commented Oct 10, 2022

I'm a bit confused. There's no git_ext::Error?

There's one for blob.rs and one for name.rs. Neither of those pertain to a function called reference.

However, we often do this:

use std_ext::ResultExt as _;
use git_ext as ext;

repo.reference(remote, sigref).or_matches(ext::is_not_found, || None)

@FintanH
Copy link
Collaborator

FintanH commented Oct 10, 2022

Ok, after the discussion here, I think we should not re-export the Error and NotFound errors from blob.rs because that error is suppose to only pertain to that small API.

@cloudhead
Copy link
Contributor Author

Yes, it's re-exported from the top-level crate, so I know it as git_ext::Error :D

@cloudhead
Copy link
Contributor Author

cloudhead commented Oct 11, 2022

In that case I think we could create our own Git error type inside heartwood, and use that. No need to change anything with git_ext, just not export the errors from the top level, or alias them as eg. BlobError if we do.

@cloudhead
Copy link
Contributor Author

Actually it would still be useful to have that is_not_found method, for when we use the git_ext blob functions.

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

2 participants