canic_testkit/pic/
errors.rs1use candid::Principal;
2
3use super::{PicSerialGuardError, startup::PicStartError};
4
5#[derive(Debug, Eq, PartialEq)]
10pub struct PicInstallError {
11 canister_id: Principal,
12 message: String,
13}
14
15#[derive(Debug)]
20pub enum StandaloneCanisterFixtureError {
21 SerialGuard(PicSerialGuardError),
22 Start(PicStartError),
23 Install(PicInstallError),
24}
25
26impl PicInstallError {
27 #[must_use]
29 pub const fn new(canister_id: Principal, message: String) -> Self {
30 Self {
31 canister_id,
32 message,
33 }
34 }
35
36 #[must_use]
38 pub const fn canister_id(&self) -> Principal {
39 self.canister_id
40 }
41
42 #[must_use]
44 pub fn message(&self) -> &str {
45 &self.message
46 }
47}
48
49impl std::fmt::Display for PicInstallError {
50 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51 write!(
52 f,
53 "failed to install canister {}: {}",
54 self.canister_id, self.message
55 )
56 }
57}
58
59impl std::error::Error for PicInstallError {}
60
61impl std::fmt::Display for StandaloneCanisterFixtureError {
62 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
63 match self {
64 Self::SerialGuard(err) => write!(f, "{err}"),
65 Self::Start(err) => write!(f, "{err}"),
66 Self::Install(err) => write!(f, "{err}"),
67 }
68 }
69}
70
71impl std::error::Error for StandaloneCanisterFixtureError {
72 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
73 match self {
74 Self::SerialGuard(err) => Some(err),
75 Self::Start(err) => Some(err),
76 Self::Install(err) => Some(err),
77 }
78 }
79}