system_update_committer/metadata/
errors.rsuse std::time::Duration;
use thiserror::Error;
use zx::Status;
use {fidl_fuchsia_paver as paver, fidl_fuchsia_update_verify as verify};
#[derive(Error, Debug)]
pub enum BootManagerError {
#[error("BootManager returned non-ok status while calling {method_name:}")]
Status {
method_name: &'static str,
#[source]
status: Status,
},
#[error("fidl error while calling BootManager method {method_name:}")]
Fidl {
method_name: &'static str,
#[source]
error: fidl::Error,
},
#[error("the status field of QueryConfigurationStatusAndBootAttempts was not set")]
StatusNotSet,
}
#[derive(Error, Debug)]
pub enum PolicyError {
#[error("the policy engine failed to build")]
Build(#[source] BootManagerError),
#[error("the current configuration ({_0:?}) is unbootable. This should never happen.")]
CurrentConfigurationUnbootable(paver::Configuration),
}
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum VerifySource {
Blobfs,
Netstack,
}
#[derive(Error, Debug)]
pub enum VerifyErrors {
#[error("one or more verifications failed: {_0:?}")]
VerifyErrors(Vec<VerifyError>),
}
#[derive(Error, Debug)]
pub enum VerifyError {
#[error("the {_0:?} verification failed in {_2:?}")]
VerifyError(VerifySource, #[source] VerifyFailureReason, Duration),
}
#[derive(Error, Debug)]
pub enum VerifyFailureReason {
#[error("the fidl call failed")]
Fidl(#[source] fidl::Error),
#[error("the verify request timed out")]
Timeout,
#[error("the verification failed: {0:?}")]
Verify(verify::VerifyError),
}
#[derive(Error, Debug)]
pub enum MetadataError {
#[error("while doing health verification")]
Verify(#[source] VerifyErrors),
#[error("while signalling EventPair peer")]
SignalPeer(#[source] Status),
#[error("while sending the unblock")]
Unblock,
#[error("while doing commit")]
Commit(#[source] BootManagerError),
#[error("while interfacing with policy")]
Policy(#[source] PolicyError),
}
pub trait BootManagerResultExt {
type T;
fn into_boot_manager_result(
self,
method_name: &'static str,
) -> Result<Self::T, BootManagerError>;
}
impl BootManagerResultExt for Result<i32, fidl::Error> {
type T = ();
fn into_boot_manager_result(
self: Result<i32, fidl::Error>,
method_name: &'static str,
) -> Result<(), BootManagerError> {
match self.map(Status::ok) {
Ok(Ok(())) => Ok(()),
Ok(Err(status)) => Err(BootManagerError::Status { status, method_name }),
Err(error) => Err(BootManagerError::Fidl { error, method_name }),
}
}
}
impl<T> BootManagerResultExt for Result<Result<T, i32>, fidl::Error> {
type T = T;
fn into_boot_manager_result(
self: Result<Result<Self::T, i32>, fidl::Error>,
method_name: &'static str,
) -> Result<Self::T, BootManagerError> {
match self {
Ok(Ok(value)) => Ok(value),
Ok(Err(raw)) => {
Err(BootManagerError::Status { status: Status::from_raw(raw), method_name })
}
Err(error) => Err(BootManagerError::Fidl { error, method_name }),
}
}
}