raz_core/
error.rs

1//! Error types for RAZ Core
2
3use std::path::PathBuf;
4use thiserror::Error;
5
6/// Main error type for RAZ operations
7#[derive(Error, Debug)]
8pub enum RazError {
9    #[error("IO error: {0}")]
10    Io(#[from] std::io::Error),
11
12    #[error("Configuration error: {message}")]
13    Config { message: String },
14
15    #[error("Project analysis failed: {message}")]
16    Analysis { message: String },
17
18    #[error("Command execution failed: {command}")]
19    Execution { command: String },
20
21    #[error("Provider error: {provider}: {message}")]
22    Provider { provider: String, message: String },
23
24    #[error("Invalid workspace: {path}")]
25    InvalidWorkspace { path: PathBuf },
26
27    #[error("Parsing error: {message}")]
28    Parse { message: String },
29
30    #[error("Feature not available: {feature}")]
31    FeatureUnavailable { feature: String },
32
33    #[error("Timeout: {operation}")]
34    Timeout { operation: String },
35
36    #[error("Internal error: {message}")]
37    Internal { message: String },
38}
39
40impl RazError {
41    pub fn config(message: impl Into<String>) -> Self {
42        Self::Config {
43            message: message.into(),
44        }
45    }
46
47    pub fn analysis(message: impl Into<String>) -> Self {
48        Self::Analysis {
49            message: message.into(),
50        }
51    }
52
53    pub fn execution(command: impl Into<String>) -> Self {
54        Self::Execution {
55            command: command.into(),
56        }
57    }
58
59    pub fn provider(provider: impl Into<String>, message: impl Into<String>) -> Self {
60        Self::Provider {
61            provider: provider.into(),
62            message: message.into(),
63        }
64    }
65
66    pub fn invalid_workspace(path: impl Into<PathBuf>) -> Self {
67        Self::InvalidWorkspace { path: path.into() }
68    }
69
70    pub fn parse(message: impl Into<String>) -> Self {
71        Self::Parse {
72            message: message.into(),
73        }
74    }
75
76    pub fn feature_unavailable(feature: impl Into<String>) -> Self {
77        Self::FeatureUnavailable {
78            feature: feature.into(),
79        }
80    }
81
82    pub fn timeout(operation: impl Into<String>) -> Self {
83        Self::Timeout {
84            operation: operation.into(),
85        }
86    }
87
88    pub fn internal(message: impl Into<String>) -> Self {
89        Self::Internal {
90            message: message.into(),
91        }
92    }
93}
94
95/// Result type alias for RAZ operations
96pub type RazResult<T> = Result<T, RazError>;