Description
Summary 💡
I'm trying to use various methods in git_repository. I usually use thiserror
to build an Error
type for my crate using #[from]
to be able to losslessly wrap every error my crate encounters, this is a pretty common idiom so I'm confident you've encountered it. When another crate I use uses the same pattern, this is pretty easy, I just extend my Error
enum with the 1 new case for that crate:
#[derive(thiserror::Error, Debug)]
enum Error {
// ... existing variants
NewCrateError(#[from] NewCrate::Error)
}
And then I can just stick ?
on any fallible operation and the conversion into my crate's Error
type magically happens. I'm running into 2 problems trying to use git-repository
this way:
- There is not 1 error type for the crate with N variants (1 variant per error), but instead N totally separate error types. This means I have to add a ton of variants to my enum.
- Some of the error types in
git-repository
are generic, e.g.git_repository::git_odb::find::existing::Error<git_repository::git_odb::store::find::Error>
so there's not even a finite number of them, further exploding the number of variants I need to add.
I wouldn't say git-repository
is doing anything "wrong", which is why this is a feature request. I don't know if there's a good motivation for doing errors this way, it just makes it more difficult to apply the idiom that I've learned for lossless error propagation.
If I could write one impl
that would let me box any error coming from git-repository
that would also work nicely, but as is now I think the only trait they have in common is the std::error::Error
trait, so AFAIK there is no good way to only do this for git-repository
errors automatically.
Motivation 🔦
Lossless error handling, generally avoiding boxing where I can. I could switch to something like anyhow
, but I'm writing a library crate so I prefer to keep user's options open.