Skip to main content

wp_self_update/
error.rs

1use derive_more::From;
2use orion_error::{OrionError, StructError, UvsReason};
3
4#[derive(Debug, Clone, PartialEq, From, OrionError)]
5pub enum UpdateReason {
6    #[orion_error(identity = "conf.update_invalid_request")]
7    InvalidRequest,
8    #[orion_error(identity = "sys.update_install_failed")]
9    InstallFailed,
10    #[orion_error(identity = "sys.update_remote_fetch_failed")]
11    RemoteFetchFailed,
12    #[orion_error(identity = "sys.update_integrity_check_failed")]
13    IntegrityCheckFailed,
14    #[orion_error(identity = "logic.update_state_conflict")]
15    StateConflict,
16    #[orion_error(transparent)]
17    Uvs(UvsReason),
18}
19
20pub type UpdateError = StructError<UpdateReason>;
21pub type UpdateResult<T> = Result<T, UpdateError>;
22
23pub(crate) fn invalid_request(detail: impl Into<String>) -> UpdateError {
24    StructError::from(UpdateReason::InvalidRequest).with_detail(detail)
25}
26
27pub(crate) fn install_failed(detail: impl Into<String>) -> UpdateError {
28    StructError::from(UpdateReason::InstallFailed).with_detail(detail)
29}
30
31pub(crate) fn remote_fetch_failed(detail: impl Into<String>) -> UpdateError {
32    StructError::from(UpdateReason::RemoteFetchFailed).with_detail(detail)
33}
34
35pub(crate) fn integrity_check_failed(detail: impl Into<String>) -> UpdateError {
36    StructError::from(UpdateReason::IntegrityCheckFailed).with_detail(detail)
37}
38
39pub(crate) fn state_conflict(detail: impl Into<String>) -> UpdateError {
40    StructError::from(UpdateReason::StateConflict).with_detail(detail)
41}