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("archive exceeds the {} byte limit", limit.get())]
43 ArchiveTooLarge { limit: crate::ArchiveLimit },
44 #[error("revision walk: {0}")]
45 RevWalk(String),
46 #[error("upload-pack selection exceeded its {0}")]
47 Selection(SelectionLimit),
48 #[error("object not found: {0}")]
49 ObjectNotFound(knot_types::Oid),
50 #[error("remove loose object {oid}: {message}")]
51 RemoveObject {
52 oid: knot_types::Oid,
53 message: String,
54 },
55 #[error("object {oid} is corrupt: {message}")]
56 Corrupt {
57 oid: knot_types::Oid,
58 message: String,
59 },
60 #[error("object {oid} isn't {expected}")]
61 ObjectType {
62 oid: knot_types::Oid,
63 expected: &'static str,
64 },
65 #[error("decode object: {0}")]
66 Decode(String),
67 #[error("git backend: {0}")]
68 Backend(String),
69 #[error("object staging: {0}")]
70 Staging(String),
71 #[error("repository config at {path}: {message}")]
72 Config { path: PathBuf, message: String },
73 #[error("repository maintenance: {0}")]
74 Maintenance(String),
75}
76
77impl From<knot_resource::FsError> for GitError {
78 fn from(error: knot_resource::FsError) -> Self {
79 GitError::Write {
80 path: error.path,
81 message: error.source.to_string(),
82 }
83 }
84}
85
86pub(crate) fn backend(error: impl std::fmt::Display) -> GitError {
87 GitError::Backend(error.to_string())
88}