elefant_tools/
error.rs

1use crate::storage::DataFormat;
2use thiserror::Error;
3
4/// All the errors that can occur in the elefant-tools library
5#[non_exhaustive]
6#[derive(Error, Debug)]
7pub enum ElefantToolsError {
8    #[error("Error from postgres: `{0}`")]
9    PostgresError(#[from] tokio_postgres::Error),
10
11    #[error("Error from postgres: `{query}` when executing query: `{source}`")]
12    PostgresErrorWithQuery {
13        query: String,
14        #[source]
15        source: tokio_postgres::Error,
16    },
17
18    #[error(
19        "Invalid number of results returned from query. Expected `{expected}`, got `{actual}`"
20    )]
21    InvalidNumberOfResults { actual: usize, expected: usize },
22
23    #[error("Unknown constraint type '{0}'")]
24    UnknownConstraintType(String),
25
26    #[error("Unknown foreign key action '{0}'")]
27    UnknownForeignKeyAction(String),
28
29    #[error("Unknown function kind '{0}'")]
30    UnknownFunctionKind(String),
31
32    #[error("Unknown volatility '{0}'")]
33    UnknownVolatility(String),
34
35    #[error("Unknown parallel '{0}'")]
36    UnknownParallel(String),
37
38    #[error("Unknown aggregate function final modify '{0}'")]
39    UnknownAggregateFinalFunctionModify(String),
40
41    #[error("Unknown trigger level '{0}'")]
42    UnknownTriggerLevel(String),
43
44    #[error("Unknown trigger timing '{0}'")]
45    UnknownTriggerTiming(String),
46
47    #[error("Unknown trigger event '{0}'")]
48    UnknownTriggerEvent(String),
49
50    #[error("Unknown table type '{0}'")]
51    InvalidTableType(String),
52
53    #[error("Unknown keyword type '{0}'")]
54    InvalidKeywordType(String),
55
56    #[error("Unknown table partitioning strategy '{0}'")]
57    InvalidTablePartitioningStrategy(String),
58
59    #[error("The table '{0}' is a partitioned table and does not have a parent table")]
60    PartitionedTableWithoutParent(String),
61
62    #[error(
63        "The table '{table}' is a partitioned table and has multiple parent tables: {parents:?}"
64    )]
65    PartitionedTableHasMultipleParent { table: String, parents: Vec<String> },
66
67    #[error("The table '{0}' is a partitioned table and does not have a partition expression")]
68    PartitionedTableWithoutExpression(String),
69
70    #[error("The table '{0}' is a partitioned table and does not have partition columns")]
71    PartitionedTableWithoutPartitionColumns(String),
72
73    #[error("The table '{0}' is a partitioned table and has both partition columns and a partition expression")]
74    PartitionedTableWithBothPartitionColumnsAndExpression(String),
75
76    #[error("Unsupported postgres version: {0}. Minimum supported version is 12")]
77    UnsupportedPostgresVersion(i32),
78
79    #[error("Invalid response from postgres when checking version")]
80    InvalidPostgresVersionResponse,
81
82    #[error("Hypertable '{table_name}' dimension '{dimension_number}' does not have an interval")]
83    HypertableDimensionWithoutInterval {
84        table_name: String,
85        dimension_number: i64,
86    },
87
88    #[error("io error: `{0}`")]
89    IoError(#[from] std::io::Error),
90
91    #[error("Data formats are not compatible between source and target. Supported by target: {supported_by_target:?}, supported by source: {supported_by_source:?}, required format: {required_format:?}")]
92    DataFormatsNotCompatible {
93        supported_by_target: Vec<DataFormat>,
94        supported_by_source: Vec<DataFormat>,
95        required_format: Option<DataFormat>,
96    },
97
98    #[error("join error: `{0}`")]
99    JoinError(#[from] tokio::task::JoinError),
100
101    #[error("Aggregate function '{0}' is missing transition type")]
102    AggregateFunctionMissingTransitionType(String),
103
104    #[error("Aggregate function '{0}' is missing transition function")]
105    AggregateFunctionMissingTransitionFunction(String),
106}
107
108/// A result type that uses the ElefantToolsError as the error type
109pub type Result<T = ()> = std::result::Result<T, ElefantToolsError>;