wow_wdl/
error.rs

1//! Error handling for WDL parsing
2
3use std::io;
4use thiserror::Error;
5
6/// Errors that can occur when working with WDL files
7#[derive(Debug, Error)]
8pub enum WdlError {
9    /// An I/O error occurred
10    #[error("I/O error: {0}")]
11    Io(#[from] io::Error),
12
13    /// Invalid magic value in the file header
14    #[error("Invalid magic value: expected '{expected}', found '{found}'")]
15    InvalidMagic {
16        /// The expected magic value
17        expected: String,
18        /// The actual magic value found
19        found: String,
20    },
21
22    /// Unsupported WDL version
23    #[error("Unsupported WDL version: {0}")]
24    UnsupportedVersion(u32),
25
26    /// Error when parsing WDL data
27    #[error("Parse error: {0}")]
28    ParseError(String),
29
30    /// Data validation failed
31    #[error("Validation error: {0}")]
32    ValidationError(String),
33
34    /// Error when converting between WDL versions
35    #[error("Version conversion error: {0}")]
36    VersionConversionError(String),
37
38    /// Unexpected end of file
39    #[error("Unexpected end of file")]
40    UnexpectedEof,
41
42    /// Unexpected chunk found
43    #[error("Unexpected chunk type: {0}")]
44    UnexpectedChunk(String),
45}
46
47/// Type alias for Results from WDL operations
48pub type Result<T> = std::result::Result<T, WdlError>;
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_error_display() {
56        let error = WdlError::ParseError("Test error".to_string());
57        assert_eq!(format!("{error}"), "Parse error: Test error");
58
59        let error = WdlError::InvalidMagic {
60            expected: "MVER".to_string(),
61            found: "ABCD".to_string(),
62        };
63        assert_eq!(
64            format!("{error}"),
65            "Invalid magic value: expected 'MVER', found 'ABCD'"
66        );
67    }
68}