| 1 | #![allow(clippy::module_name_repetitions)] |
| 2 | |
| 3 | use thiserror::Error; |
| 4 | |
| 5 | use crate::Frequency; |
| 6 | |
| 7 | #[derive(Error, Debug, Clone, PartialEq, Eq)] |
| 8 | pub enum ValidationError { |
| 9 | #[error("BYSETPOS should only be used in conjunction with another BYxxx rule part.")] |
| 10 | BySetPosWithoutByRule, |
| 11 | #[error("`{field}` can't be `{value}`, must be larger or smaller then `{value}`.")] |
| 12 | InvalidFieldValue { field: String, value: String }, |
| 13 | #[error( |
| 14 | "`{field}` is `{value}`, but is not allowed outside the range: `{start_idx}..={end_idx}`." |
| 15 | )] |
| 16 | InvalidFieldValueRange { |
| 17 | field: String, |
| 18 | value: String, |
| 19 | start_idx: String, |
| 20 | end_idx: String, |
| 21 | }, |
| 22 | #[error( |
| 23 | "`{field}` is `{value}`, but with the current frequency ({freq}) is not allowed \ |
| 24 | outside the range: `{start_idx}..={end_idx}`." |
| 25 | )] |
| 26 | InvalidFieldValueRangeWithFreq { |
| 27 | field: String, |
| 28 | value: String, |
| 29 | freq: Frequency, |
| 30 | start_idx: String, |
| 31 | end_idx: String, |
| 32 | }, |
| 33 | #[error("`{by_rule}` can not be used with the current frequency ({freq}).")] |
| 34 | InvalidByRuleAndFrequency { by_rule: String, freq: Frequency }, |
| 35 | #[error("`UNTIL` is `{until}`, but `DTSTART` (`{dt_start}`) is later. That should not be happening.")] |
| 36 | UntilBeforeStart { until: String, dt_start: String }, |
| 37 | #[error( |
| 38 | "`INTERVAL` is `{0}`, is higher than expected, make sure this is correct. \ |
| 39 | See 'validator limits' in docs for more info." |
| 40 | )] |
| 41 | TooBigInterval(u16), |
| 42 | #[error( |
| 43 | "`DTSTART` year is `{0}`, is higher/lower than expected, make sure this is correct. \ |
| 44 | See 'validator limits' in docs for more info." |
| 45 | )] |
| 46 | StartYearOutOfRange(i32), |
| 47 | #[error( |
| 48 | "Unable to generate a timeset for the RRULE. Please specify a BYHOUR, BYMINUTE or BYSECOND" |
| 49 | )] |
| 50 | UnableToGenerateTimeset, |
| 51 | #[cfg(feature = "by-easter")] |
| 52 | #[error("`BYEASTER` can only be used when `BYHOUR`, `BYMINUTE` and `BYSECOND` are set.")] |
| 53 | InvalidByRuleWithByEaster, |
| 54 | #[error( |
| 55 | "The value of `DTSTART` was specified in {dt_start_tz} timezone, but `UNTIL` was specified in timezone {until_tz}. Allowed timezones for `UNTIL` with the given start date timezone are: `{expected:?}`" |
| 56 | )] |
| 57 | DtStartUntilMismatchTimezone { |
| 58 | dt_start_tz: String, |
| 59 | until_tz: String, |
| 60 | expected: Vec<String>, |
| 61 | }, |
| 62 | } |