apt_sources_lists/
errors.rs

1use std::io;
2use std::path::PathBuf;
3
4/// An error that may occur when parsing apt sources.
5#[derive(Debug, Error)]
6pub enum SourceError {
7    #[error(display = "I/O error occurred: {}", _0)]
8    Io(io::Error),
9    #[error(display = "missing field in apt source list: '{}'", field)]
10    MissingField { field: &'static str },
11    #[error(
12        display = "invalid field in apt source list: '{}' is invalid for '{}'",
13        value,
14        field
15    )]
16    InvalidValue { field: &'static str, value: String },
17    #[error(display = "entry did not exist in sources")]
18    EntryNotFound,
19    #[error(display = "failed to write changes to {:?}: {}", path, why)]
20    EntryWrite { path: PathBuf, why: io::Error },
21    #[error(display = "source file was not found")]
22    FileNotFound,
23    #[error(display = "failed to parse source list at {:?}: {}", path, why)]
24    SourcesList {
25        path: PathBuf,
26        why: Box<SourcesListError>,
27    },
28    #[error(display = "failed to open / read source list at {:?}: {}", path, why)]
29    SourcesListOpen { path: PathBuf, why: io::Error },
30}
31
32#[derive(Debug, Error)]
33pub enum SourcesListError {
34    #[error(display = "parsing error on line {}: {}", line, why)]
35    BadLine { line: usize, why: SourceError },
36}
37
38impl From<io::Error> for SourceError {
39    fn from(why: io::Error) -> Self {
40        SourceError::Io(why)
41    }
42}
43
44/// Equivalent to `Result<T, SourceError>`.
45pub type SourceResult<T> = Result<T, SourceError>;