1use thiserror::Error;
2
3#[derive(Error, Debug)]
5pub enum JmixError {
6 #[error("IO error: {0}")]
7 Io(#[from] std::io::Error),
8
9 #[error("JSON error: {0}")]
10 Json(#[from] serde_json::Error),
11
12 #[error("Validation error: {0}")]
13 Validation(#[from] ValidationError),
14
15 #[error("Cryptography error: {0}")]
16 Cryptography(#[from] CryptographyError),
17
18 #[error("Encryption error: {0}")]
19 Encryption(#[from] crate::encryption::EncryptionError),
20
21 #[error("DICOM processing error: {0}")]
22 Dicom(String),
23
24 #[error("Configuration error: {0}")]
25 Config(String),
26
27 #[error("JMIX error: {0}")]
28 General(String),
29
30 #[error("Other error: {0}")]
31 Other(String),
32}
33
34#[derive(Error, Debug)]
36pub enum ValidationError {
37 #[error("Schema file not found: {path}")]
38 SchemaNotFound { path: String },
39
40 #[error("Schema validation failed for {schema}: {errors:?}")]
41 SchemaValidation { schema: String, errors: Vec<String> },
42
43 #[error("Invalid JSON schema: {0}")]
44 InvalidSchema(String),
45}
46
47#[derive(Error, Debug)]
49pub enum CryptographyError {
50 #[error("Key generation failed: {0}")]
51 KeyGeneration(String),
52
53 #[error("Encryption failed: {0}")]
54 Encryption(String),
55
56 #[error("Decryption failed: {0}")]
57 Decryption(String),
58
59 #[error("Invalid key format: {0}")]
60 InvalidKey(String),
61
62 #[error("JWS creation failed: {0}")]
63 JwsCreation(String),
64
65 #[error("JWS verification failed: {0}")]
66 JwsVerification(String),
67
68 #[error("Hash verification failed")]
69 HashVerification,
70}
71
72pub type JmixResult<T> = Result<T, JmixError>;