1use crate::{JourneyError, Version, parsing::error::ParsingError};
2use bincode::error::{DecodeError, EncodeError};
3use chrono::NaiveDate;
4use thiserror::Error;
5use zip::result::ZipError;
6
7#[derive(Debug, Error)]
8pub enum HrdfError {
9 #[error("File {file}, at line {line_number}: {line}. Parsing error: {error:?}")]
10 Parsing {
11 error: ParsingError,
12 file: String,
13 line: String,
14 line_number: usize,
15 },
16 #[error("Io error: {0}")]
17 Io(#[from] std::io::Error),
18 #[error("Missing key \"start_date\"")]
19 MissingStartDate,
20 #[error("Missing key \"end_date\"")]
21 MissingEndDate,
22 #[error("JourneyError {0}")]
23 Journey(#[from] JourneyError),
24 #[error("Failed to add {1} days to {0}")]
25 FailedToAddDays(NaiveDate, u64),
26 #[error("Failed to subtract {1} days to {0}")]
27 FailedToSubDays(NaiveDate, u64),
28 #[error("BitFieldId {0} not found")]
29 BitFieldIdNotFound(i32),
30 #[error("Failed to read cache: {0}")]
31 ReadCache(#[from] DecodeError),
32 #[error("Failed to write cache: {0}")]
33 WriteCacher(#[from] EncodeError),
34 #[error("Failed decompress data: {0}")]
35 Decompress(#[from] ZipError),
36 #[error("Failed to download data: {0}")]
37 Download(#[from] reqwest::Error),
38 #[error("Missing stop id: {0}")]
39 MissingStopId(i32),
40 #[error("Missing departure time at index: {0}")]
41 MissingDepartureTime(usize),
42 #[error("Missing arrival time at index: {0}")]
43 MissingArrivalTime(usize),
44 #[error("Missing route")]
45 MissingRoute,
46 #[error("Out of rage date: {0}")]
47 OutOfRangeDate(NaiveDate),
48 #[error("Invalid year provided")]
49 InvalidYear,
50 #[error("Version not supported: {0}")]
51 SupportedVersion(Version),
52}
53
54pub type HResult<T> = Result<T, HrdfError>;