-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy patherror.rs
More file actions
80 lines (75 loc) · 2.76 KB
/
Copy patherror.rs
File metadata and controls
80 lines (75 loc) · 2.76 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Module for the error management
use thiserror::Error;
/// Specific line from a CSV file that could not be read
#[derive(Debug, Clone)]
pub struct LineError {
/// Headers of the CSV file
pub headers: Vec<String>,
/// Values of the line that could not be parsed
pub values: Vec<String>,
}
/// An error that can occur when processing GTFS data.
#[derive(Error, Debug, Clone)]
pub enum Error {
/// A mandatory file is not present in the archive
#[error("Cound not find file {0}")]
MissingFile(String),
/// A file references an Id that is not present
#[error("The id {0} is not known")]
ReferenceError(String),
/// The given path to the GTFS is neither a file nor a directory
#[error("Could not read GTFS: {0} is neither a file nor a directory")]
NotFileNorDirectory(String),
/// The time is not given in the HH:MM:SS format
#[error("'{0}' is not a valid time; HH:MM:SS format is expected.")]
InvalidTime(String),
/// The color is not given in the RRGGBB format, without a leading `#`
#[error("'{0}' is not a valid color; RRGGBB format is expected, without a leading `#`")]
InvalidColor(String),
/// Generic Input/Output error while reading a file
#[error("impossible to read file")]
IO(std::sync::Arc<std::io::Error>),
/// Impossible to read a file
#[error("impossible to read '{file_name}'")]
NamedFileIO {
/// The file name that could not be read
file_name: String,
/// The inital error that caused the unability to read the file
#[source]
source: std::sync::Arc<dyn std::error::Error + Send + Sync>,
},
/// Impossible to fetch the remote archive by the URL
#[cfg(feature = "read-url")]
#[error("impossible to remotely access file")]
Fetch(std::sync::Arc<reqwest::Error>),
/// Impossible to read a CSV file
#[error("impossible to read csv file '{file_name}'")]
CSVError {
/// File name that could not be parsed as CSV
file_name: String,
/// The initial error by the csv library
#[source]
source: std::sync::Arc<csv::Error>,
/// The line that could not be parsed by the csv library
line_in_error: Option<LineError>,
},
/// Error when trying to unzip the GTFS archive
#[error(transparent)]
Zip(std::sync::Arc<zip::result::ZipError>),
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::IO(std::sync::Arc::new(err))
}
}
#[cfg(feature = "read-url")]
impl From<reqwest::Error> for Error {
fn from(err: reqwest::Error) -> Self {
Error::Fetch(std::sync::Arc::new(err))
}
}
impl From<zip::result::ZipError> for Error {
fn from(err: zip::result::ZipError) -> Self {
Error::Zip(std::sync::Arc::new(err))
}
}