#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("state store: {0}")]
Sqlite(#[from] rusqlite::Error),
#[error(
"state store schema version {found} is newer than this version supports ({supported}); \
upgrade trestle"
)]
UnsupportedVersion {
found: u32,
supported: u32,
},
#[error(
"`{0}` is not a valid name: use lowercase letters, digits and dashes, starting with a letter"
)]
InvalidName(String),
#[error("{kind} `{name}` already exists")]
Duplicate {
kind: &'static str,
name: String,
},
#[error("no {kind} `{id}`")]
NotFound {
kind: &'static str,
id: String,
},
#[error(
"{kind} `{name}` has {instances} instance{}: remove {} first",
if *instances == 1 { "" } else { "s" },
if *instances == 1 { "it" } else { "them" }
)]
HasInstances {
kind: &'static str,
name: String,
instances: usize,
},
#[error("no free slot: the host runs at most {} instances", olai_stack_topology::MAX_SLOT + 1)]
SlotsExhausted,
#[error(transparent)]
Manifest(#[from] olai_stack_topology::ManifestError),
#[error(transparent)]
Workspace(#[from] olai_stack_topology::WorkspaceError),
#[error("state store JSON: {0}")]
Json(#[from] serde_json::Error),
#[error("{path}: {source}")]
Io {
path: std::path::PathBuf,
#[source]
source: std::io::Error,
},
#[error("can't export: {0}")]
Export(String),
}
impl Error {
pub(crate) fn io(path: impl Into<std::path::PathBuf>, source: std::io::Error) -> Self {
Error::Io {
path: path.into(),
source,
}
}
}
pub type Result<T, E = Error> = std::result::Result<T, E>;