proof_of_sql_parser/posql_time/
error.rs

1use alloc::string::{String, ToString};
2use serde::{Deserialize, Serialize};
3use snafu::Snafu;
4
5/// Errors related to time operations, including timezone and timestamp conversions.
6#[allow(clippy::module_name_repetitions)]
7#[derive(Snafu, Debug, Eq, PartialEq, Serialize, Deserialize)]
8pub enum PoSQLTimestampError {
9    /// Error when the timezone string provided cannot be parsed into a valid timezone.
10    #[snafu(display("invalid timezone string: {timezone}"))]
11    InvalidTimezone {
12        /// The invalid timezone
13        timezone: String,
14    },
15
16    /// Error indicating an invalid timezone offset was provided.
17    #[snafu(display("invalid timezone offset"))]
18    InvalidTimezoneOffset,
19
20    /// Indicates a failure to convert between different representations of time units.
21    #[snafu(display("Invalid time unit"))]
22    InvalidTimeUnit {
23        /// The underlying error
24        error: String,
25    },
26
27    /// The local time does not exist because there is a gap in the local time.
28    /// This variant may also be returned if there was an error while resolving the local time,
29    /// caused by for example missing time zone data files, an error in an OS API, or overflow.
30    #[snafu(display("Local time does not exist because there is a gap in the local time"))]
31    LocalTimeDoesNotExist,
32
33    /// The local time is ambiguous because there is a fold in the local time.
34    /// This variant contains the two possible results, in the order (earliest, latest).
35    #[snafu(display("Unix timestamp is ambiguous because there is a fold in the local time."))]
36    Ambiguous {
37        /// The underlying error
38        error: String,
39    },
40
41    /// Represents a catch-all for parsing errors not specifically covered by other variants.
42    #[snafu(display("Timestamp parsing error: {error}"))]
43    ParsingError {
44        /// The underlying error
45        error: String,
46    },
47
48    /// Represents a failure to parse a provided time unit precision value, `PoSQL` supports
49    /// Seconds, Milliseconds, Microseconds, and Nanoseconds
50    #[snafu(display("Unsupported precision for timestamp: {error}"))]
51    UnsupportedPrecision {
52        /// The underlying error
53        error: String,
54    },
55}
56
57// This exists because TryFrom<DataType> for ColumnType error is String
58impl From<PoSQLTimestampError> for String {
59    fn from(error: PoSQLTimestampError) -> Self {
60        error.to_string()
61    }
62}