use {
crate::{
core::{self, deser, storage, workspace},
Addr,
},
std::io,
};
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("unhandled error: `{0}`")]
Unhandled(String),
#[error("fixity encountered an internal error: {source}")]
Internal {
#[from]
source: Internal,
},
#[error("fixity repository was not found")]
RepositoryNotFound,
#[error("no changes to write to repository")]
NoChangesToWrite,
#[error("a commit was attempted without any changes to commit")]
NoStageToCommit,
#[error("an action is unsupported when the HEAD is detached")]
DetachedHead,
#[error("cannot replace root data structure with non-map")]
CannotReplaceRootMap,
#[error("an address if dangling: `{message}`")]
DanglingAddr {
message: String,
addr: Option<Addr>,
},
#[error("data type error: {0}")]
Type(#[from] Type),
#[error("builder error: `{message}`")]
Builder { message: String },
#[error("prolly error: `{message}`")]
Prolly { message: String },
#[error("prolly@`{addr}`, error: `{message}`")]
ProllyAddr { addr: Addr, message: String },
#[error("store error: `{0}`")]
Storage(#[from] storage::Error),
#[error("io error: `{0}`")]
Io(#[from] io::Error),
#[error("reading input error: `{err}`")]
IoInputRead { err: io::Error },
#[error(
"storage wrote {got} bytes,
but was expected to write {expected} bytes"
)]
IncompleteWrite { got: usize, expected: usize },
#[error("deser error: `{0}`")]
Deser(#[from] deser::Error),
#[cfg(feature = "serde_json")]
#[error("serde json error: `{0}`")]
SerdeJson(#[from] serde_json::error::Error),
#[cfg(feature = "borsh")]
#[error("borsh error: `{0:?}`")]
Borsh(std::io::Error),
#[cfg(feature = "borsh")]
#[error("addr:{addr}, borsh error: `{err:?}`")]
BorshAddr { addr: Addr, err: std::io::Error },
#[cfg(feature = "cjson")]
#[error("cjson error: `{0:?}`")]
Cjson(cjson::Error),
}
#[derive(Debug, thiserror::Error)]
pub enum Internal {
#[error("fixity failed to initialize a new repository: {source}")]
Init {
#[from]
source: core::fixity::InitError,
},
#[error("head: `{source}`")]
Workspace {
#[from]
source: workspace::Error,
},
#[error("primitive: `{0}`")]
Primitive(String),
#[error("path: `{0}`")]
Path(String),
#[error("input/output error: `{0}`")]
Io(String),
}
#[cfg(feature = "cjson")]
impl From<cjson::Error> for Error {
fn from(err: cjson::Error) -> Self {
Self::Cjson(err)
}
}
impl From<workspace::Error> for Error {
fn from(err: workspace::Error) -> Self {
Self::Internal { source: err.into() }
}
}
impl From<core::fixity::InitError> for Error {
fn from(err: core::fixity::InitError) -> Self {
Self::Internal { source: err.into() }
}
}
#[derive(Debug, thiserror::Error)]
pub enum Type {
#[error("expected a Value of a specific type, got another")]
UnexpectedValueVariant {
at_segment: Option<String>,
at_addr: Option<Addr>,
},
}