proof_of_sql/base/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 /// Represents a failure to parse a provided time unit precision value, `PoSQL` supports
27 /// Seconds, Milliseconds, Microseconds, and Nanoseconds
28 #[snafu(display("Unsupported precision for timestamp: {error}"))]
29 UnsupportedPrecision {
30 /// The underlying error
31 error: String,
32 },
33}
34
35// This exists because TryFrom<DataType> for ColumnType error is String
36impl From<PoSQLTimestampError> for String {
37 fn from(error: PoSQLTimestampError) -> Self {
38 error.to_string()
39 }
40}