/ src / error.rs
error.rs
  1  use std::path::PathBuf;
  2  use thiserror::Error;
  3  
  4  #[derive(Error, Debug)]
  5  pub enum AbundantisError {
  6      #[error("Configuration error: {message}")]
  7      Config {
  8          message: String,
  9          path: Option<PathBuf>,
 10      },
 11  
 12      #[error("Missing required configuration: `{field}`. {suggestion}")]
 13      MissingConfig {
 14          field: &'static str,
 15          suggestion: String,
 16      },
 17  
 18      #[error("Unknown provider `{provider}`. Valid options: turbo, nx, lerna, pnpm, npm, yarn, cargo, custom")]
 19      UnknownProvider { provider: String },
 20  
 21      #[error("Invalid glob pattern `{pattern}`: {reason}")]
 22      InvalidGlob { pattern: String, reason: String },
 23  
 24      #[error("Workspace root not found. Searched from: {search_path:?}")]
 25      WorkspaceNotFound { search_path: PathBuf },
 26  
 27      #[error("Provider config file not found: {expected_file} in {search_path:?}")]
 28      ProviderConfigNotFound {
 29          expected_file: &'static str,
 30          search_path: PathBuf,
 31      },
 32  
 33      #[error("Failed to parse provider config `{path:?}`: {reason}")]
 34      ProviderConfigParse { path: PathBuf, reason: String },
 35  
 36      #[error("Source error: {0}")]
 37      Source(#[from] SourceError),
 38  
 39      #[error("Circular dependency detected: {chain}")]
 40      CircularDependency { chain: String },
 41  
 42      #[error("Max interpolation depth ({depth}) exceeded for `{key}`")]
 43      MaxDepthExceeded { key: String, depth: u32 },
 44  
 45      #[error("Undefined variable `{key}` referenced in interpolation")]
 46      UndefinedVariable { key: String },
 47  
 48      #[error("IO error: {0}")]
 49      Io(#[from] std::io::Error),
 50  
 51      #[error("Tokio runtime error: {0}")]
 52      Runtime(String),
 53  
 54      #[error("Cache error: {0}")]
 55      Cache(String),
 56  }
 57  
 58  #[derive(Error, Debug, Clone)]
 59  pub enum SourceError {
 60      #[error("Failed to read source `{source_name}`: {reason}")]
 61      SourceRead { source_name: String, reason: String },
 62  
 63      #[error("Parse error in `{path:?}` at line {line}: {message}")]
 64      ParseError {
 65          path: PathBuf,
 66          line: u32,
 67          message: String,
 68      },
 69  
 70      #[error("Remote source error from `{provider}`: {reason}")]
 71      Remote { provider: String, reason: String },
 72  
 73      #[error("Timeout while loading source `{source_name}`")]
 74      Timeout { source_name: String },
 75  
 76      #[error("Authentication failed for source `{source_name}`")]
 77      Authentication { source_name: String },
 78  
 79      #[error("Permission denied for source `{source_name}`")]
 80      Permission { source_name: String },
 81  
 82      #[error("Unsupported operation `{operation}` for source: {reason}")]
 83      UnsupportedOperation {
 84          operation: String,
 85          source_type: String,
 86          reason: String,
 87      },
 88  
 89      #[error("Rate limited by `{provider}`, retry after {retry_after_secs}s")]
 90      RateLimited {
 91          provider: String,
 92          retry_after_secs: u64,
 93      },
 94  
 95      #[error("Invalid scope for `{provider}`: {reason}")]
 96      InvalidScope { provider: String, reason: String },
 97  
 98      #[error("Connection error to `{provider}`: {reason}")]
 99      Connection { provider: String, reason: String },
100  
101      #[error("Unknown provider: `{provider}`")]
102      UnknownProvider { provider: String },
103  }
104  
105  pub type Result<T> = std::result::Result<T, AbundantisError>;
106  
107  #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
108  pub enum DiagnosticSeverity {
109      Error,
110      Warning,
111      Info,
112      Hint,
113  }
114  
115  #[derive(Debug, Clone, PartialEq, Eq)]
116  pub struct Diagnostic {
117      pub severity: DiagnosticSeverity,
118      pub code: DiagnosticCode,
119      pub message: String,
120      pub path: PathBuf,
121      pub line: u32,
122      pub column: u32,
123  }
124  
125  #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
126  pub enum DiagnosticCode {
127      EDF001,
128      EDF002,
129      EDF003,
130      EDF004,
131  
132      RES001,
133      RES002,
134      RES003,
135  
136      WS001,
137      WS002,
138  }
139  
140  impl std::fmt::Display for DiagnosticCode {
141      fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
142          write!(f, "{:?}", self)
143      }
144  }