git_stats/error.rs
1//! The library's typed error. Callers can match on named variants; the binary
2//! (`main.rs`) wraps this in `anyhow`, following the convention that libraries
3//! use `thiserror` and only binaries reach for `anyhow`.
4
5use thiserror::Error;
6
7/// Boxed source error. gix surfaces a distinct concrete error type per
8/// operation, so boxing preserves the source chain without this enum having to
9/// enumerate (and track, across gix versions) every one of them.
10type Source = Box<dyn std::error::Error + Send + Sync + 'static>;
11
12/// Result alias for the library's [`Error`].
13pub type Result<T> = std::result::Result<T, Error>;
14
15/// Anything that can go wrong while gathering git statistics.
16#[derive(Debug, Error)]
17pub enum Error {
18 /// No git repository could be discovered from the given path.
19 #[error("could not open a git repository")]
20 OpenRepository(#[source] Source),
21
22 /// A revision (typically an endpoint of the range) could not be resolved.
23 #[error("could not resolve revision {revision:?}")]
24 ResolveRevision {
25 revision: String,
26 #[source]
27 source: Source,
28 },
29
30 /// Walking the revision range failed.
31 #[error("could not walk revision range {range:?}")]
32 WalkRange {
33 range: String,
34 #[source]
35 source: Source,
36 },
37
38 /// A commit object could not be read or decoded.
39 #[error("could not read commit data")]
40 ReadCommit(#[source] Source),
41
42 /// Computing a commit's diff stats failed.
43 #[error("could not compute diff stats")]
44 DiffStats(#[source] Source),
45
46 /// An `--author` pattern was not a valid regular expression.
47 #[error("invalid author pattern")]
48 AuthorPattern(#[from] regex::Error),
49
50 /// A `--since`/`--until` value was not a recognized date.
51 #[error("invalid date {input:?}: {message}")]
52 InvalidDate { input: String, message: String },
53}