Skip to main content

niwa_core/
error.rs

1//! Error types for niwa-core
2
3use thiserror::Error;
4
5/// Result type for niwa-core operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Error types for niwa-core
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Database error
12    #[error("Database error: {0}")]
13    Database(#[from] sqlx::Error),
14
15    /// Expertise not found
16    #[error("Expertise not found: {id} (scope: {scope})")]
17    NotFound { id: String, scope: String },
18
19    /// Expertise already exists
20    #[error("Expertise already exists: {id} (scope: {scope})")]
21    AlreadyExists { id: String, scope: String },
22
23    /// Invalid scope
24    #[error("Invalid scope: {0}")]
25    InvalidScope(String),
26
27    /// Invalid relation type
28    #[error("Invalid relation type: {0}")]
29    InvalidRelationType(String),
30
31    /// Circular dependency detected
32    #[error("Circular dependency detected: {from} -> {to}")]
33    CircularDependency { from: String, to: String },
34
35    /// Serialization error
36    #[error("Serialization error: {0}")]
37    Serialization(#[from] serde_json::Error),
38
39    /// IO error
40    #[error("IO error: {0}")]
41    Io(#[from] std::io::Error),
42
43    /// Migration error
44    #[error("Migration error: {0}")]
45    Migration(String),
46
47    /// Generic error
48    #[error("{0}")]
49    Other(String),
50}
51
52impl From<String> for Error {
53    fn from(s: String) -> Self {
54        Error::Other(s)
55    }
56}
57
58impl From<&str> for Error {
59    fn from(s: &str) -> Self {
60        Error::Other(s.to_string())
61    }
62}