1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Error types used in the gerber-types library.

use std::io::Error as IoError;

use thiserror::Error;

#[derive(Error, Debug)]
pub enum GerberError {
    #[error("Conversion between two types failed: {0}")]
    ConversionError(String),

    #[error("Bad coordinate format: {0}")]
    CoordinateFormatError(String),

    #[error("A value is out of range: {0}")]
    RangeError(String),

    #[error("Required data is missing: {0}")]
    MissingDataError(String),

    #[error("I/O error during code generation")]
    IoError(#[from] IoError),
}

pub type GerberResult<T> = Result<T, GerberError>;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_error_msg() {
        let err = GerberError::CoordinateFormatError("Something went wrong".into());
        assert_eq!(
            err.to_string(),
            "Bad coordinate format: Something went wrong"
        );
    }
}