git-ents.gitmain
⌘K
foforge
error.rs85 lines · 3.0 KB · rusthistorycomment on this file
1//! `ents-forge`'s error type: everything that can prevent a comment
2//! command from reaching a result.
3//!
4//! Mirrors `ents-effect`'s split: an [`Error`] here means the command could
5//! not *reach* an outcome at all (a store or object read failed, an anchor
6//! could not be captured or projected, `receive` itself could not reach a
7//! judgment) — as opposed to a reached [`ents_receive::Outcome`], which
8//! [`crate::comment::add`] returns as `Ok` for its caller to interpret (the
9//! CLI's own `outcome_to_result`, for instance).
10
11use std::path::PathBuf;
12
13/// Everything that can prevent an `ents-forge` operation from reaching a
14/// result.
15#[derive(Debug, thiserror::Error)]
16pub enum Error {
17 /// The ref store's read or write half failed.
18 #[error("ref store operation failed: {0}")]
19 Refs(#[from] gix_ref_store::Error),
20
21 /// A typed-tree entity (a [`crate::comment::Comment`] or
22 /// [`ents_anchor::Anchor`]) could not be (de)serialized.
23 #[error("typed-tree operation failed: {0}")]
24 Tree(#[from] facet_git_tree::Error),
25
26 /// Capturing or projecting a code anchor failed.
27 #[error("anchor operation failed: {0}")]
28 Anchor(#[from] ents_anchor::Error),
29
30 /// Building a comment's refname failed (`ents_model::namespace`).
31 #[error("model error: {0}")]
32 Model(#[from] ents_model::Error),
33
34 /// Opening the local git repository failed (`gix::open`, needed for
35 /// `ents_anchor::capture`/`project`). Boxed: `gix::open::Error` is
36 /// large enough on its own to trip `clippy::result_large_err` for
37 /// every fallible function in this crate if stored inline, the same
38 /// reasoning `ents-effect`'s own error type documents for its boxed
39 /// `ents_receive::Error` variant.
40 #[error(transparent)]
41 Repo(Box<gix::open::Error>),
42
43 /// `ents_receive::propose_entity` (or `receive` itself) could not
44 /// reach an outcome. Boxed; see [`Error::Repo`]'s own doc.
45 #[error("receive failed: {0}")]
46 Receive(Box<ents_receive::Error>),
47
48 /// The named entity (a comment) does not exist.
49 #[error("not found: {what}")]
50 NotFound {
51 /// What was being looked up.
52 what: String,
53 },
54
55 /// A malformed argument that fails a semantic check this crate makes
56 /// (an invalid line range, an unparsable oid, ...).
57 #[error("invalid argument: {0}")]
58 InvalidArgument(String),
59
60 /// A local (non-git, non-gate) I/O failure: reading or writing a file
61 /// outside the object database.
62 #[error("io error at {path}: {source}")]
63 Io {
64 /// The path being read or written.
65 path: PathBuf,
66 /// The underlying I/O failure.
67 #[source]
68 source: std::io::Error,
69 },
70}
71
72impl From<gix::open::Error> for Error {
73 fn from(source: gix::open::Error) -> Self {
74 Self::Repo(Box::new(source))
75 }
76}
77
78impl From<ents_receive::Error> for Error {
79 fn from(source: ents_receive::Error) -> Self {
80 Self::Receive(Box::new(source))
81 }
82}
83
84/// The `Result` alias every fallible `ents-forge` operation returns.
85pub type Result<T> = std::result::Result<T, Error>;