audb_core/tools/
errors.rs

1/// Error types for audb operations
2///
3/// This module provides structured error types using thiserror for better error handling
4/// and contextual error messages throughout the application.
5use thiserror::Error;
6
7/// Errors related to device operations
8#[derive(Error, Debug)]
9pub enum DeviceError {
10    /// Device was not found in the device store
11    #[error("Device not found: {0}")]
12    NotFound(String),
13
14    /// Root password is not configured for the device
15    #[error("Root password not configured for device: {0}")]
16    RootPasswordNotConfigured(String),
17
18    /// Failed to connect to the device
19    #[error("Connection failed: {0}")]
20    ConnectionFailed(String),
21
22    /// SSH operation error
23    #[error("SSH error: {0}")]
24    SshError(#[from] anyhow::Error),
25
26    /// Device validation error
27    #[error("Device validation failed: {0}")]
28    ValidationError(String),
29}
30
31/// Errors related to configuration file operations
32#[derive(Error, Debug)]
33pub enum ConfigError {
34    /// Failed to read configuration file
35    #[error("Failed to read config: {0}")]
36    ReadError(#[from] std::io::Error),
37
38    /// Failed to parse configuration file
39    #[error("Invalid config format: {0}")]
40    ParseError(#[from] serde_json::Error),
41
42    /// Configuration validation failed
43    #[error("Config validation failed: {0}")]
44    ValidationError(String),
45
46    /// Configuration file not found
47    #[error("Config file not found at: {0}")]
48    NotFound(String),
49}
50
51/// Errors related to input operations (tap, swipe, screenshot)
52#[derive(Error, Debug)]
53pub enum InputError {
54    /// Invalid coordinates provided
55    #[error("Invalid coordinates: {0}")]
56    InvalidCoordinates(String),
57
58    /// Script execution failed
59    #[error("Script execution failed: {0}")]
60    ScriptExecutionFailed(String),
61
62    /// D-Bus command failed
63    #[error("D-Bus command failed: {0}")]
64    DbusCommandFailed(String),
65
66    /// Device operation error
67    #[error(transparent)]
68    DeviceError(#[from] DeviceError),
69}
70
71/// Errors related to package installation
72#[derive(Error, Debug)]
73pub enum InstallError {
74    /// RPM file is invalid or not found
75    #[error("Invalid RPM file: {0}")]
76    InvalidRpmFile(String),
77
78    /// Package installation failed
79    #[error("Package installation failed: {0}")]
80    InstallationFailed(String),
81
82    /// Device operation error
83    #[error(transparent)]
84    DeviceError(#[from] DeviceError),
85}