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 Matching Trusted Publisher Certificate")]
26    NoTrustedPublisherCertificate = 3,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
30pub enum VerificationError {
31    Unverified,
32    MissingCosign2Header,
33    InternalError,
34}
35
36#[derive(Debug, Clone, PartialEq, Eq, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
37pub enum LaunchError {
38    UnknownAppId,
39    Verification(VerificationError),
40    NameRegistration,
41    NoTrustedPublisherCertificate,
42    OutOfMemory,
43    InternalError,
44}
45
46impl From<xous::Error> for LaunchError {
47    fn from(value: xous::Error) -> Self {
48        match value {
49            xous::Error::OutOfMemory => LaunchError::OutOfMemory,
50            _ => LaunchError::InternalError,
51        }
52    }
53}
54
55impl From<std::str::Utf8Error> for LaunchError {
56    fn from(_: std::str::Utf8Error) -> Self { LaunchError::InternalError }
57}
58
59impl From<LaunchError> for AppManagerError {
60    fn from(value: LaunchError) -> Self {
61        match value {
62            LaunchError::UnknownAppId => AppManagerError::UnknownAppId,
63            LaunchError::Verification(_) => AppManagerError::VerificationFailed,
64            LaunchError::NoTrustedPublisherCertificate => AppManagerError::NoTrustedPublisherCertificate,
65            _ => AppManagerError::InternalError,
66        }
67    }
68}
69
70#[cfg(not(keyos))]
71impl From<std::io::Error> for LaunchError {
72    fn from(_value: std::io::Error) -> Self { LaunchError::InternalError }
73}
74
75#[cfg(not(keyos))]
76impl From<serde_json::Error> for LaunchError {
77    fn from(_value: serde_json::Error) -> Self { LaunchError::InternalError }
78}