Skip to main content

ic_dbms_client/
errors.rs

1/// Result type for IC DBMS Canister client operations.
2pub type IcDbmsCanisterClientResult<T> = Result<T, IcDbmCanisterClientError>;
3
4/// Errors that can occur when interacting with an IC DBMS Canister.
5#[derive(thiserror::Error, Debug)]
6pub enum IcDbmCanisterClientError {
7    #[error("IC Call failed: {0}")]
8    Call(#[from] ic_cdk::call::CallFailed),
9    #[error("Candid decode failed: {0}")]
10    Candid(#[from] ic_cdk::call::CandidDecodeFailed),
11    #[error("IC DBMS Canister error: {0}")]
12    Canister(#[from] ic_dbms_api::prelude::IcDbmsError),
13    #[error("IC Agent error: {0}")]
14    #[cfg(feature = "ic-agent")]
15    IcAgent(#[from] IcAgentError),
16    #[error("Pocket IC error: {0}")]
17    #[cfg(feature = "pocket-ic")]
18    PocketIc(#[from] PocketIcError),
19}
20
21/// Errors that can occur when using the ic-agent client.
22#[cfg(feature = "ic-agent")]
23#[cfg_attr(docsrs, doc(cfg(feature = "ic-agent")))]
24#[derive(thiserror::Error, Debug)]
25pub enum IcAgentError {
26    #[error(transparent)]
27    Agent(#[from] ic_agent::AgentError),
28    #[error("Candid error: {0}")]
29    Candid(#[from] candid::Error),
30}
31
32/// Errors that can occur when using the pocket-ic client.
33#[cfg(feature = "pocket-ic")]
34#[cfg_attr(docsrs, doc(cfg(feature = "pocket-ic")))]
35#[derive(thiserror::Error, Debug)]
36pub enum PocketIcError {
37    #[error("Pocket IC call failed: {0}")]
38    Candid(#[from] candid::Error),
39    #[error("Pocket IC reject response: {0}")]
40    Reject(pocket_ic::RejectResponse),
41}
42
43#[cfg(feature = "pocket-ic")]
44#[cfg_attr(docsrs, doc(cfg(feature = "pocket-ic")))]
45impl From<pocket_ic::RejectResponse> for PocketIcError {
46    fn from(reject: pocket_ic::RejectResponse) -> Self {
47        PocketIcError::Reject(reject)
48    }
49}