Skip to main content

ic_storage/adapter/
error.rs

1///
2/// `CollectionError`
3///
4/// Collection admission or region access failed. Codec and engine failures
5/// trap and follow the host's failure contract.
6///
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq, thiserror::Error)]
9pub enum CollectionError {
10    /// The bytes belong to another format.
11    #[error("unrecognized collection format")]
12    Format,
13    /// Capacity could not be reserved.
14    #[error("collection growth refused")]
15    Growth,
16    /// Creation was attempted in nonempty memory.
17    #[error("collection memory is not empty")]
18    NotEmpty,
19    /// Cell envelope admission failed before reading its payload.
20    #[error("{0}")]
21    Cell(#[from] crate::StableCellPayloadError),
22}
23
24pub(super) type Result<T> = std::result::Result<T, CollectionError>;
25
26pub(super) const fn ensure(condition: bool, error: CollectionError) -> Result<()> {
27    if condition { Ok(()) } else { Err(error) }
28}