This repository has no description
1use std::path::PathBuf;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
4pub enum SelectionLimit {
5 Objects,
6 Time,
7}
8
9impl std::fmt::Display for SelectionLimit {
10 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
11 f.write_str(match self {
12 SelectionLimit::Objects => "object-set limit",
13 SelectionLimit::Time => "wall-clock budget",
14 })
15 }
16}
17
18#[derive(Debug, thiserror::Error)]
19pub enum GitError {
20 #[error("repository already exists at {0}")]
21 AlreadyExists(PathBuf),
22 #[error("open repository at {path}: {message}")]
23 Open { path: PathBuf, message: String },
24 #[error("create repository at {path}: {message}")]
25 Create { path: PathBuf, message: String },
26 #[error("remove repository at {path}: {message}")]
27 Remove { path: PathBuf, message: String },
28 #[error("reference {name}: {message}")]
29 Reference { name: String, message: String },
30 #[error("atomic ref transaction: {0}")]
31 AtomicRefs(String),
32 #[error("fsync {path}: {message}")]
33 Fsync { path: PathBuf, message: String },
34 #[error("atomic write to {path}: {message}")]
35 Write { path: PathBuf, message: String },
36 #[error("repo DID {0} maps to unsafe on-disk path component")]
37 UnsafeRepoDid(String),
38 #[error("repo DID {0} is reserved for knot meta-repo and is never served as user repo")]
39 ReservedDid(String),
40 #[error("{0} exceeds maximum supported depth")]
41 DepthExceeded(&'static str),
42 #[error("revision walk: {0}")]
43 RevWalk(String),
44 #[error("upload-pack selection exceeded its {0}")]
45 Selection(SelectionLimit),
46 #[error("object not found: {0}")]
47 ObjectNotFound(knot_types::Oid),
48 #[error("remove loose object {oid}: {message}")]
49 RemoveObject {
50 oid: knot_types::Oid,
51 message: String,
52 },
53 #[error("object {oid} is corrupt: {message}")]
54 Corrupt {
55 oid: knot_types::Oid,
56 message: String,
57 },
58 #[error("object {oid} isn't {expected}")]
59 ObjectType {
60 oid: knot_types::Oid,
61 expected: &'static str,
62 },
63 #[error("decode object: {0}")]
64 Decode(String),
65 #[error("git backend: {0}")]
66 Backend(String),
67 #[error("object staging: {0}")]
68 Staging(String),
69 #[error("repository config at {path}: {message}")]
70 Config { path: PathBuf, message: String },
71 #[error("repository maintenance: {0}")]
72 Maintenance(String),
73}
74
75impl From<knot_resource::FsError> for GitError {
76 fn from(error: knot_resource::FsError) -> Self {
77 GitError::Write {
78 path: error.path,
79 message: error.source.to_string(),
80 }
81 }
82}
83
84pub(crate) fn backend(error: impl std::fmt::Display) -> GitError {
85 GitError::Backend(error.to_string())
86}