Skip to main content

lingxia_shell/
error.rs

1use thiserror::Error;
2
3pub type ShellResult<T> = Result<T, ShellError>;
4
5#[derive(Debug, Error, Clone, PartialEq, Eq)]
6pub enum ShellError {
7    #[error("shell sidebar action id must not be empty")]
8    EmptySidebarActionId,
9    #[error("shell sidebar action field '{field}' must not be empty")]
10    EmptySidebarActionField { field: &'static str },
11    #[error("duplicate shell sidebar action id '{id}'")]
12    DuplicateSidebarActionId { id: String },
13    #[error("shell sidebar action '{id}' was not found")]
14    SidebarActionNotFound { id: String },
15    #[error("shell sidebar action update for '{id}' is empty")]
16    EmptySidebarActionUpdate { id: String },
17    #[error("shell sidebar action header accepts at most {max} items")]
18    SidebarActionHeaderLimit { max: usize },
19    #[error("shell sidebar action icon '{icon}' must be an lxapp-accessible local resource path")]
20    InvalidSidebarActionIcon { icon: String },
21    #[error("shell runtime is not initialized")]
22    NotInitialized,
23    #[error("shell host operation failed: {0}")]
24    Host(String),
25    #[error("shell sidebar action '{id}' is disabled")]
26    SidebarActionDisabled { id: String },
27    #[error("stale shell sidebar action generation {generation}; current generation is {current}")]
28    StaleSidebarActionIntent { generation: u64, current: u64 },
29    #[error("shell state changed concurrently (expected generation {expected}, found {actual})")]
30    ConcurrentMutation { expected: u64, actual: u64 },
31    #[error("shell Pins changed concurrently")]
32    ConcurrentPinMutation,
33    #[error("shell Pin limit reached ({max})")]
34    LimitReached { max: usize },
35    #[error("unsupported shell state version {version}")]
36    UnsupportedVersion { version: u32 },
37    #[error("invalid shell state: {0}")]
38    InvalidState(String),
39    #[error("shell state I/O failed: {0}")]
40    Io(String),
41}
42
43impl From<std::io::Error> for ShellError {
44    fn from(value: std::io::Error) -> Self {
45        Self::Io(value.to_string())
46    }
47}
48
49impl From<serde_json::Error> for ShellError {
50    fn from(value: serde_json::Error) -> Self {
51        Self::InvalidState(value.to_string())
52    }
53}