crates/kernel/ents-anchor/src/error.rs
error.rshistorycomment on this file
| 1 | //! The error type every `ents-anchor` operation returns. |
| 2 | |
| 3 | use gix::ObjectId; |
| 4 | |
| 5 | /// Everything that can go wrong capturing or projecting an [`crate::Anchor`]. |
| 6 | #[derive(Debug, thiserror::Error)] |
| 7 | pub enum Error { |
| 8 | /// A revision string ([`crate::capture`]'s or [`crate::project`]'s |
| 9 | /// `revision`/`target` argument) could not be resolved to a commit in |
| 10 | /// the repository. |
| 11 | #[error("could not resolve {0:?}")] |
| 12 | Resolve(String), |
| 13 | /// A git object could not be read or decoded. |
| 14 | #[error("git object operation failed: {0}")] |
| 15 | Object(String), |
| 16 | /// The tree diff between the anchor commit and the target commit |
| 17 | /// failed. |
| 18 | #[error("tree diff failed: {0}")] |
| 19 | Diff(String), |
| 20 | /// The anchor names a path that is not a regular file in the commit it |
| 21 | /// was captured against (`anchor.definition`'s path validation). |
| 22 | #[error("no file at {path:?} in {commit}")] |
| 23 | MissingPath { |
| 24 | /// The commit the path was looked up in. |
| 25 | commit: ObjectId, |
| 26 | /// The path that is not a file there. |
| 27 | path: String, |
| 28 | }, |
| 29 | /// The line range does not fit the file it is anchored to |
| 30 | /// (`anchor.definition`'s line-range validation). |
| 31 | #[error("lines {start}..={end} do not fit {path:?} ({len} lines)")] |
| 32 | LinesOutOfRange { |
| 33 | /// The file the range was checked against. |
| 34 | path: String, |
| 35 | /// The 1-based first line of the range. |
| 36 | start: u64, |
| 37 | /// The 1-based last line of the range. |
| 38 | end: u64, |
| 39 | /// How many lines the file actually has. |
| 40 | len: u64, |
| 41 | }, |
| 42 | /// [`crate::project_exact`]'s anchor commit is no longer present in the |
| 43 | /// repository (garbage collected) — [`crate::project`] catches this and |
| 44 | /// retries with [`crate::project_from_context`] |
| 45 | /// (`anchor.fuzzy-fallback`); a caller invoking |
| 46 | /// [`crate::project_exact`] directly sees it as an ordinary error. |
| 47 | #[error("the anchor commit {0} no longer exists")] |
| 48 | AnchorCommitMissing(ObjectId), |
| 49 | /// [`crate::capture_worktree`] or [`crate::project_worktree`] was asked |
| 50 | /// to read the working tree of a repository that has none (a bare |
| 51 | /// repository). Capture or project against a revision instead |
| 52 | /// (`anchor.working-tree` applies only where a working tree exists). |
| 53 | #[error("the repository has no working tree")] |
| 54 | NoWorkingTree, |
| 55 | /// Encoding or decoding a [`crate::Binding`] through the underlying |
| 56 | /// `facet-git-tree` codec failed — a malformed payload tree, or a |
| 57 | /// backend error from the `gix` object store the codec was given. |
| 58 | #[error("binding codec error: {0}")] |
| 59 | Codec(#[from] facet_git_tree::Error), |
| 60 | /// A stored tree's entry names matched none of [`crate::Binding`]'s five |
| 61 | /// variant shapes ([`crate::Binding::deserialize`]'s sniffing rule): |
| 62 | /// neither `blob`+`content` (`Position`), `base_tree` (`Delta`), |
| 63 | /// `witness`+`tree` (`Tree`), exactly `{commit, tree}` (`Hybrid`), nor |
| 64 | /// exactly `{commit}` (`Commit`). |
| 65 | #[error("tree {id} does not match any known binding shape (entries: {entries:?})")] |
| 66 | UnknownBindingShape { |
| 67 | /// The tree that could not be recognized as any binding variant. |
| 68 | id: ObjectId, |
| 69 | /// The entry names actually present in that tree. |
| 70 | entries: Vec<String>, |
| 71 | }, |
| 72 | } |
| 73 | |
| 74 | /// The `Result` alias every `ents-anchor` operation returns. |
| 75 | pub type Result<T> = std::result::Result<T, Error>; |