wsi_dicom/error.rs
1use std::path::PathBuf;
2
3/// Error type returned by public `wsi-dicom` APIs.
4#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum Error {
7 /// Export or validation options are internally inconsistent.
8 #[error("invalid DICOM export options: {reason}")]
9 InvalidOptions {
10 /// Human-readable reason safe to show to users.
11 reason: String,
12 },
13 /// Metadata is missing required fields or cannot be mapped safely.
14 #[error("invalid DICOM metadata: {reason}")]
15 Metadata {
16 /// Human-readable reason safe to show to users.
17 reason: String,
18 },
19 /// Source or prepared pixel data cannot be represented by the requested output.
20 #[error("unsupported pixel data: {reason}")]
21 UnsupportedPixelData {
22 /// Human-readable reason safe to show to users.
23 reason: String,
24 },
25 /// The requested route, transfer syntax, or backend is unsupported.
26 #[error("unsupported export request: {reason}")]
27 Unsupported {
28 /// Human-readable reason safe to show to users.
29 reason: String,
30 },
31 /// The source slide could not be opened.
32 #[error("failed to open source slide {path}: {message}")]
33 SourceOpen {
34 /// Source path that failed to open.
35 path: PathBuf,
36 /// Underlying open error message.
37 message: String,
38 },
39 /// DICOM export identity generation failed.
40 #[error("failed to generate DICOM export identity: {reason}")]
41 Identity {
42 /// Human-readable identity generation failure.
43 reason: String,
44 },
45 /// The source slide failed while reading pixels or metadata.
46 #[error("slide read failed: {message}")]
47 SlideRead {
48 /// Underlying read error message.
49 message: String,
50 },
51 /// JPEG 2000 or HTJ2K encoding failed before a frame location was available.
52 #[error("JPEG 2000 encode failed: {message}")]
53 Encode {
54 /// Underlying encode error message.
55 message: String,
56 },
57 /// JPEG 2000 or HTJ2K encoding failed for one DICOM frame.
58 #[error(
59 "JPEG 2000 encode failed at level {level}, tile row {row}, tile column {col}: {message}"
60 )]
61 FrameEncode {
62 /// Source pyramid level being encoded.
63 level: u32,
64 /// DICOM tile row being encoded.
65 row: u64,
66 /// DICOM tile column being encoded.
67 col: u64,
68 /// Underlying encode error message.
69 message: String,
70 },
71 /// Filesystem I/O failed at a known path.
72 #[error("I/O error at {path}: {source}")]
73 Io {
74 /// Path involved in the failed I/O operation.
75 path: PathBuf,
76 /// Underlying I/O error.
77 source: std::io::Error,
78 },
79 /// DICOM object construction or writing failed.
80 #[error("DICOM write failed for {path}: {message}")]
81 DicomWrite {
82 /// Destination path being written.
83 path: PathBuf,
84 /// Underlying DICOM writer message.
85 message: String,
86 },
87 /// JSON parsing failed at a known path.
88 #[error("JSON parse failed for {path}: {source}")]
89 Json {
90 /// JSON path being read.
91 path: PathBuf,
92 /// Underlying JSON parser error.
93 source: serde_json::Error,
94 },
95 /// JSON serialization failed.
96 #[error("JSON serialization failed: {message}")]
97 JsonSerialize {
98 /// Serialization error message.
99 message: String,
100 },
101 /// A staged export could not be committed or rolled back completely.
102 #[error("export transaction requires recovery at {recovery_path}: {reason}")]
103 ExportTransaction {
104 /// Directory containing the durable manifest, staged files, and backups.
105 recovery_path: PathBuf,
106 /// Human-readable commit or rollback failure details.
107 reason: String,
108 },
109 /// External DICOM validation failed.
110 #[error("DICOM validation failed: {reason}")]
111 Validation {
112 /// Human-readable validation failure reason.
113 reason: String,
114 },
115}