1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, Error>;
7
8#[derive(Error, Debug)]
10pub enum Error {
11 #[error("Database error: {0}")]
13 Database(#[from] sqlx::Error),
14
15 #[error("Expertise not found: {id} (scope: {scope})")]
17 NotFound { id: String, scope: String },
18
19 #[error("Expertise already exists: {id} (scope: {scope})")]
21 AlreadyExists { id: String, scope: String },
22
23 #[error("Invalid scope: {0}")]
25 InvalidScope(String),
26
27 #[error("Invalid relation type: {0}")]
29 InvalidRelationType(String),
30
31 #[error("Circular dependency detected: {from} -> {to}")]
33 CircularDependency { from: String, to: String },
34
35 #[error("Serialization error: {0}")]
37 Serialization(#[from] serde_json::Error),
38
39 #[error("IO error: {0}")]
41 Io(#[from] std::io::Error),
42
43 #[error("Migration error: {0}")]
45 Migration(String),
46
47 #[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}