system_update_committer/metadata/
errors.rs1use fidl_fuchsia_paver as paver;
6use thiserror::Error;
7use zx::Status;
8
9#[derive(Error, Debug)]
11pub enum BootManagerError {
12 #[error("BootManager returned non-ok status while calling {method_name:}")]
13 Status {
14 method_name: &'static str,
15 #[source]
16 status: Status,
17 },
18
19 #[error("fidl error while calling BootManager method {method_name:}")]
20 Fidl {
21 method_name: &'static str,
22 #[source]
23 error: fidl::Error,
24 },
25
26 #[error("the status field of QueryConfigurationStatusAndBootAttempts was not set")]
27 StatusNotSet,
28}
29
30#[derive(Error, Debug)]
32pub enum PolicyError {
33 #[error("the policy engine failed to build")]
34 Build(#[source] BootManagerError),
35
36 #[error(
37 "the current configuration ({_0:?}) is unbootable with reason {_1:?}. This should never happen."
38 )]
39 CurrentConfigurationUnbootable(paver::Configuration, Option<paver::UnbootableReason>),
40}
41
42#[derive(Error, Debug)]
44pub enum HealthVerificationError {
45 #[error("fidl error while querying health checks")]
46 Fidl(#[source] fidl::Error),
47 #[error("HealthVerification responded with unhealthy status")]
48 Unhealthy(#[source] Status),
49}
50
51#[derive(Error, Debug)]
53pub enum MetadataError {
54 #[error("while doing health verification")]
55 HealthVerification(#[source] HealthVerificationError),
56
57 #[error("while signalling EventPair peer")]
58 SignalPeer(#[source] Status),
59
60 #[error("while sending the unblock")]
61 Unblock,
62
63 #[error("while doing commit")]
64 Commit(#[source] BootManagerError),
65
66 #[error("while interfacing with policy")]
67 Policy(#[source] PolicyError),
68
69 #[error("the commit timed out")]
70 Timeout,
71}
72
73pub trait BootManagerResultExt {
75 type T;
76
77 fn into_boot_manager_result(
78 self,
79 method_name: &'static str,
80 ) -> Result<Self::T, BootManagerError>;
81}
82
83impl BootManagerResultExt for Result<i32, fidl::Error> {
84 type T = ();
85
86 fn into_boot_manager_result(
87 self: Result<i32, fidl::Error>,
88 method_name: &'static str,
89 ) -> Result<(), BootManagerError> {
90 match self.map(Status::ok) {
91 Ok(Ok(())) => Ok(()),
92 Ok(Err(status)) => Err(BootManagerError::Status { status, method_name }),
93 Err(error) => Err(BootManagerError::Fidl { error, method_name }),
94 }
95 }
96}
97
98impl<T> BootManagerResultExt for Result<Result<T, i32>, fidl::Error> {
99 type T = T;
100
101 fn into_boot_manager_result(
102 self: Result<Result<Self::T, i32>, fidl::Error>,
103 method_name: &'static str,
104 ) -> Result<Self::T, BootManagerError> {
105 match self {
106 Ok(Ok(value)) => Ok(value),
107 Ok(Err(raw)) => {
108 Err(BootManagerError::Status { status: Status::from_raw(raw), method_name })
109 }
110 Err(error) => Err(BootManagerError::Fidl { error, method_name }),
111 }
112 }
113}