apt_sources/
error.rs

1//! A module for handling errors in `apt-sources` crate of `deb822-rs` project.
2//! It intends to address error handling in meaningful manner, less vague than just passing
3//! `String` as error.
4
5/// Errors for APT sources parsing and conversion to `Repository`
6#[derive(Debug)]
7pub enum RepositoryError {
8    /// Invalid repository format
9    InvalidFormat,
10    /// Invalid repository URI
11    InvalidUri,
12    /// Missing repository URI - mandatory
13    MissingUri,
14    /// Unrecognized repository type
15    InvalidType,
16    /// The `Signed-By` field is incorrect
17    InvalidSignature,
18    /// Errors in lossy serializer or deserializer
19    Lossy(deb822_lossless::lossy::Error),
20    /// Errors in lossless parser
21    Lossless(deb822_lossless::lossless::Error),
22    /// I/O Error
23    Io(std::io::Error)
24}
25
26impl From<std::io::Error> for RepositoryError {
27    fn from(e: std::io::Error) -> Self {
28        Self::Io(e)
29    }
30}
31
32impl std::fmt::Display for RepositoryError {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
34        match self {
35            Self::InvalidFormat => write!(f, "Invalid repository format"),
36            Self::InvalidUri => write!(f, "Invalid repository URI"),
37            Self::MissingUri => write!(f, "Missing repository URI"),
38            Self::InvalidType => write!(f, "Invalid repository type"),
39            Self::InvalidSignature => write!(f, "The field `Signed-By` is incorrect"),
40            Self::Lossy(e) => write!(f, "Lossy parser error: {}", e),
41            Self::Lossless(e) => write!(f, "Lossless parser error: {}", e),
42            Self::Io(e) => write!(f, "IO error: {}", e),
43        }
44    }
45}