1use crate::object::{ChangeId, ContentHash, TreeError};
5
6#[derive(Debug, thiserror::Error)]
8pub enum HeddleError {
9 #[error("object not found: {0}")]
10 NotFound(String),
11 #[error("state not found: {0}")]
12 StateNotFound(ChangeId),
13 #[error("invalid object: {0}")]
14 InvalidObject(String),
15 #[error("repository not found at {0}")]
16 RepositoryNotFound(std::path::PathBuf),
17 #[error("repository already exists at {0}")]
18 RepositoryExists(std::path::PathBuf),
19 #[error("io error: {0}")]
20 Io(#[from] std::io::Error),
21 #[error("serialization error: {0}")]
22 Serialization(String),
23 #[error("configuration error: {0}")]
24 Config(String),
25 #[error("conflict: {0}")]
26 Conflict(String),
27 #[error("compression error: {0}")]
28 Compression(String),
29 #[error("invalid ref name: {0}")]
30 InvalidRefName(String),
31 #[error("file too large: {0} bytes")]
32 InvalidFileSize(u64),
33 #[error("symlink target escapes repository: {0}")]
34 InvalidSymlinkTarget(std::path::PathBuf),
35 #[error("object corruption: expected {expected}, found {found}")]
36 Corruption {
37 expected: ContentHash,
38 found: ContentHash,
39 },
40 #[error("missing {object_type} object: {id}")]
41 MissingObject { object_type: String, id: String },
42 #[error("invalid tree entry: {0}")]
43 InvalidTreeEntry(#[from] TreeError),
44}
45
46impl From<rmp_serde::encode::Error> for HeddleError {
47 fn from(e: rmp_serde::encode::Error) -> Self {
48 HeddleError::Serialization(e.to_string())
49 }
50}
51
52impl From<rmp_serde::decode::Error> for HeddleError {
53 fn from(e: rmp_serde::decode::Error) -> Self {
54 HeddleError::Serialization(e.to_string())
55 }
56}
57
58impl From<toml::de::Error> for HeddleError {
59 fn from(e: toml::de::Error) -> Self {
60 HeddleError::Config(e.to_string())
61 }
62}
63
64impl From<toml::ser::Error> for HeddleError {
65 fn from(e: toml::ser::Error) -> Self {
66 HeddleError::Config(e.to_string())
67 }
68}
69
70impl From<serde_json::Error> for HeddleError {
71 fn from(e: serde_json::Error) -> Self {
72 HeddleError::Serialization(e.to_string())
73 }
74}
75
76pub type Result<T> = std::result::Result<T, HeddleError>;