gerber_types/
errors.rs

1//! Error types used in the gerber-types library.
2
3use std::io::Error as IoError;
4
5use thiserror::Error;
6
7#[derive(Error, Debug)]
8pub enum GerberError {
9    #[error("Conversion between two types failed: {0}")]
10    ConversionError(String),
11
12    #[error("Bad coordinate format: {0}")]
13    CoordinateFormatError(String),
14
15    #[error("A value is out of range: {0}")]
16    RangeError(String),
17
18    #[error("Required data is missing: {0}")]
19    MissingDataError(String),
20
21    #[error("I/O error during code generation")]
22    IoError(#[from] IoError),
23
24    #[error("Empty coordinates")]
25    EmptyCoordinates,
26}
27
28pub type GerberResult<T> = Result<T, GerberError>;
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_error_msg() {
36        let err = GerberError::CoordinateFormatError("Something went wrong".into());
37        assert_eq!(
38            err.to_string(),
39            "Bad coordinate format: Something went wrong"
40        );
41    }
42}