Get rid of `file::verify::EitherError` in favor of having `graph::verify::Error` manually copy file errors into the graph error object.
Showing the changes to git-commitgraph/src/graph (1 of 3 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | 2 | file::{self, commit}, |
| 3 | − graph, Graph, GENERATION_NUMBER_MAX, | |
| 3 | + graph, Graph, ImpossibleVariantError, GENERATION_NUMBER_MAX, | |
| 4 | 4 | }; |
| 5 | 5 | use git_object::owned; |
| 6 | 6 | use std::cmp::{max, min}; |
| @@ -22,7 +22,15 @@ pub enum Error<E: std::error::Error + 'static> { · 15 unmodified lines | ||
| 22 | 22 | #[error(transparent)] |
| 23 | 23 | Commit(#[from] commit::Error), |
| 24 | 24 | #[error("{}: {err}", .path.display())] |
| 25 | − File { err: file::verify::Error, path: PathBuf }, | |
| 25 | + File { | |
| 26 | + // Use zero-size error type. We will never return | |
| 27 | + // `graph::verify::Error::File(file::verify::Error::Processor(...))`, because we are the | |
| 28 | + // file's processor, and we convert`file::verify::Error::Processor<graph::verify::Error>` | |
| 29 | + // variants into direct `graph::verify::Error` values. | |
| 30 | + // TODO: Use never type when it becomes available. | |
| 31 | + err: file::verify::Error<ImpossibleVariantError>, | |
| 32 | + path: PathBuf, | |
| 33 | + }, | |
| 26 | 34 | #[error("Commit {id}'s generation should be {expected} but is {actual}")] |
| 27 | 35 | Generation { actual: u32, expected: u32, id: owned::Id }, |
| 28 | 36 | #[error( |
| @@ -132,12 +140,32 @@ impl Graph { · 103 unmodified lines | ||
| 132 | 140 | |
| 133 | 141 | Ok(()) |
| 134 | 142 | }) |
| 135 | − .map_err(|e| match e { | |
| 136 | − file::verify::EitherError::Internal(err) => Error::File { | |
| 137 | − err, | |
| 138 | − path: file.path().to_owned(), | |
| 143 | + .map_err(|err| Error::File { | |
| 144 | + err: match err { | |
| 145 | + file::verify::Error::Processor(e) => return e, | |
| 146 | + file::verify::Error::RootTreeId { id, root_tree_id } => { | |
| 147 | + file::verify::Error::RootTreeId { id, root_tree_id } | |
| 148 | + } | |
| 149 | + file::verify::Error::Mismatch { actual, expected } => { | |
| 150 | + file::verify::Error::Mismatch { actual, expected } | |
| 151 | + } | |
| 152 | + file::verify::Error::Generation { generation, id } => { | |
| 153 | + file::verify::Error::Generation { generation, id } | |
| 154 | + } | |
| 155 | + file::verify::Error::Filename(expected) => file::verify::Error::Filename(expected), | |
| 156 | + file::verify::Error::Commit(err) => file::verify::Error::Commit(err), | |
| 157 | + file::verify::Error::CommitId { id, pos } => file::verify::Error::CommitId { id, pos }, | |
| 158 | + file::verify::Error::CommitsOutOfOrder { | |
| 159 | + id, | |
| 160 | + pos, | |
| 161 | + predecessor_id, | |
| 162 | + } => file::verify::Error::CommitsOutOfOrder { | |
| 163 | + id, | |
| 164 | + pos, | |
| 165 | + predecessor_id, | |
| 166 | + }, | |
| 139 | 167 | }, |
| 140 | − file::verify::EitherError::Processor(e) => e, | |
| 168 | + path: file.path().to_owned(), | |
| 141 | 169 | })?; |
| 142 | 170 | |
| 143 | 171 | max_generation = max(max_generation, file_stats.max_generation); |