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