Skip to main content
KeyOS API Reference

app_manager/
error.rs

1// SPDX-FileCopyrightText: 2025 Foundation Devices, Inc. <hello@foundation.xyz>
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#[derive(
5    Debug,
6    Clone,
7    Copy,
8    thiserror::Error,
9    rkyv::Archive,
10    rkyv::Serialize,
11    rkyv::Deserialize,
12    num_derive::FromPrimitive,
13    num_derive::ToPrimitive,
14)]
15pub enum AppManagerError {
16    #[error("Unknown AppId")]
17    UnknownAppId = 0,
18
19    #[error("Verification Failed")]
20    VerificationFailed = 1,
21
22    #[error("Internal Error")]
23    InternalError = 2,
24
25    #[error("No Certificate")]
26    NoCertificate = 3,
27
28    #[error("Publisher Certificate Expired")]
29    PublisherCertificateExpired = 4,
30
31    #[error("Publisher Certificate Not Active Yet")]
32    PublisherCertificateNotYetActive = 5,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
36pub enum VerificationError {
37    Unverified,
38    MissingCosign2Header,
39    InternalError,
40}
41
42#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
43pub enum LaunchError {
44    UnknownAppId,
45    Verification(VerificationError),
46    NameRegistration,
47    NoCertificate,
48    PublisherCertificateExpired,
49    PublisherCertificateNotYetActive,
50    OutOfMemory,
51    InternalError,
52}
53
54impl From<xous::Error> for LaunchError {
55    fn from(value: xous::Error) -> Self {
56        match value {
57            xous::Error::OutOfMemory => LaunchError::OutOfMemory,
58            _ => LaunchError::InternalError,
59        }
60    }
61}
62
63impl From<std::str::Utf8Error> for LaunchError {
64    fn from(_: std::str::Utf8Error) -> Self { LaunchError::InternalError }
65}
66
67impl From<LaunchError> for AppManagerError {
68    fn from(value: LaunchError) -> Self {
69        match value {
70            LaunchError::UnknownAppId => AppManagerError::UnknownAppId,
71            LaunchError::Verification(_) => AppManagerError::VerificationFailed,
72            LaunchError::NoCertificate => AppManagerError::NoCertificate,
73            LaunchError::PublisherCertificateExpired => AppManagerError::PublisherCertificateExpired,
74            LaunchError::PublisherCertificateNotYetActive => {
75                AppManagerError::PublisherCertificateNotYetActive
76            }
77            _ => AppManagerError::InternalError,
78        }
79    }
80}
81
82#[cfg(not(keyos))]
83impl From<std::io::Error> for LaunchError {
84    fn from(_value: std::io::Error) -> Self { LaunchError::InternalError }
85}
86
87#[cfg(not(keyos))]
88impl From<serde_json::Error> for LaunchError {
89    fn from(_value: serde_json::Error) -> Self { LaunchError::InternalError }
90}