1use std::path::PathBuf;
4
5use cadvm_store::StoreError;
6
7#[derive(Debug, thiserror::Error)]
9pub enum CoreError {
10 #[error("not a cadvm repository (no .cadvm directory found in `{0}` or any parent)")]
11 NotARepository(PathBuf),
12
13 #[error("a cadvm repository already exists at `{0}`")]
14 AlreadyInitialized(PathBuf),
15
16 #[error("the current branch `{0}` has no commits yet")]
17 EmptyBranch(String),
18
19 #[error("HEAD has no parent commit")]
20 NoParent,
21
22 #[error("could not resolve revision `{0}`")]
23 UnknownRevision(String),
24
25 #[error("ambiguous short hash `{prefix}` matches {count} commits")]
26 AmbiguousRevision { prefix: String, count: usize },
27
28 #[error("branch `{0}` already exists")]
29 BranchExists(String),
30
31 #[error("branch `{0}` does not exist")]
32 NoSuchBranch(String),
33
34 #[error("invalid branch name `{0}`")]
35 InvalidBranchName(String),
36
37 #[error("cannot delete the currently checked-out branch `{0}`")]
38 CannotDeleteCurrentBranch(String),
39
40 #[error("path `{path}` does not exist in revision `{rev}`")]
41 PathNotInRevision { path: PathBuf, rev: String },
42
43 #[error("cannot {action}: working tree has uncommitted changes (use --force to override)")]
44 DirtyWorkingTree { action: String },
45
46 #[error(
47 "refusing to overwrite locally modified file `{0}` (use --force to discard local changes)"
48 )]
49 WouldOverwriteDirtyFile(PathBuf),
50
51 #[error("only reverting HEAD is supported (requested `{0}`)")]
52 RevertNonHead(String),
53
54 #[error(
55 "geometry helper `{0}` not found — build it (see cpp/build.sh) and set CADVM_GEOM_BIN"
56 )]
57 GeomBinaryNotFound(PathBuf),
58
59 #[error("geometry helper failed: {0}")]
60 GeomFailed(String),
61
62 #[error("i/o error at `{path}`: {source}")]
63 Io {
64 path: PathBuf,
65 #[source]
66 source: std::io::Error,
67 },
68
69 #[error(transparent)]
70 Store(#[from] StoreError),
71
72 #[error(transparent)]
73 Json(#[from] serde_json::Error),
74}
75
76impl CoreError {
77 pub(crate) fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
78 CoreError::Io {
79 path: path.into(),
80 source,
81 }
82 }
83}
84
85pub type Result<T> = std::result::Result<T, CoreError>;