Skip to main content

sway_groups_core/
error.rs

1//! Error types for sway-groups.
2
3use thiserror::Error;
4
5/// Result type alias using our error type.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Main error enum for sway-groups.
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Database error
12    #[error("Database error: {0}")]
13    Database(#[from] sea_orm::DbErr),
14
15    /// Sway IPC error
16    #[error("Sway IPC error: {0}")]
17    SwayIpc(String),
18
19    /// Workspace not found
20    #[error("Workspace not found: {0}")]
21    WorkspaceNotFound(String),
22
23    /// Group not found
24    #[error("Group not found: {0}")]
25    GroupNotFound(String),
26
27    /// Output not found
28    #[error("Output not found: {0}")]
29    OutputNotFound(String),
30
31    /// Configuration error
32    #[error("Configuration error: {0}")]
33    Config(String),
34
35    /// Invalid arguments
36    #[error("Invalid arguments: {0}")]
37    InvalidArgs(String),
38
39    /// Sway not running
40    #[error("Sway is not running or IPC socket not available")]
41    SwayNotRunning,
42
43    /// IO error
44    #[error("IO error: {0}")]
45    Io(#[from] std::io::Error),
46
47    /// JSON error
48    #[error("JSON error: {0}")]
49    Json(#[from] serde_json::Error),
50}
51
52impl serde::Serialize for Error {
53    fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
54    where
55        S: serde::Serializer,
56    {
57        serializer.serialize_str(&self.to_string())
58    }
59}