Skip to main content

executable/
error.rs

1use core::fmt::Display;
2use embedded_i18n::t;
3
4pub type Result<T> = core::result::Result<T, Error>;
5
6#[derive(Debug, Clone)]
7pub enum Error {
8    FileSystem(virtual_file_system::IoErrorKind),
9    Task(task::Error),
10    FailedToGetMainFunction,
11    InvalidStackSize,
12    PermissionDenied,
13    #[cfg(feature = "native-dev")]
14    Native(native_loader::Error),
15    #[cfg(feature = "native-dev")]
16    NativeFileTooLarge,
17}
18
19impl Display for Error {
20    fn fmt(&self, formatter: &mut core::fmt::Formatter) -> core::fmt::Result {
21        match self {
22            Error::FileSystem(error) => write!(formatter, "{error}"),
23            Error::Task(error) => write!(formatter, "{error}"),
24            Error::FailedToGetMainFunction => {
25                write!(formatter, "{}", t!("errors.failed_to_get_main_function"))
26            }
27            Error::InvalidStackSize => write!(formatter, "{}", t!("errors.invalid_stack_size")),
28            #[cfg(feature = "native-dev")]
29            Error::Native(error) => write!(formatter, "{} ({error:?})", t!("errors.native_load")),
30            #[cfg(feature = "native-dev")]
31            Error::NativeFileTooLarge => {
32                write!(formatter, "{}", t!("errors.native_file_too_large"))
33            }
34            Error::PermissionDenied => write!(formatter, "{}", t!("errors.permission_denied")),
35        }
36    }
37}
38
39impl From<virtual_file_system::IoErrorKind> for Error {
40    fn from(error: virtual_file_system::IoErrorKind) -> Self {
41        Error::FileSystem(error)
42    }
43}
44
45impl From<task::Error> for Error {
46    fn from(error: task::Error) -> Self {
47        Error::Task(error)
48    }
49}