Skip to main content

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] elefant_client::ElefantClientError),
10
11    #[error("Error from postgres: `{query}` when executing query: `{source}`")]
12    PostgresErrorWithQuery {
13        query: String,
14        #[source]
15        source: elefant_client::ElefantClientError,
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 column identity '{0}'")]
51    UnknownColumnIdentity(String),
52
53    #[error("Unknown table type '{0}'")]
54    InvalidTableType(String),
55
56    #[error("Unknown keyword type '{0}'")]
57    InvalidKeywordType(String),
58
59    #[error("Unknown table partitioning strategy '{0}'")]
60    InvalidTablePartitioningStrategy(String),
61
62    #[error("The table '{0}' is a partitioned table and does not have a parent table")]
63    PartitionedTableWithoutParent(String),
64
65    #[error(
66        "The table '{table}' is a partitioned table and has multiple parent tables: {parents:?}"
67    )]
68    PartitionedTableHasMultipleParent { table: String, parents: Vec<String> },
69
70    #[error("The table '{0}' is a partitioned table and does not have a partition expression")]
71    PartitionedTableWithoutExpression(String),
72
73    #[error("The table '{0}' is a partitioned table and does not have partition columns")]
74    PartitionedTableWithoutPartitionColumns(String),
75
76    #[error("The table '{0}' is a partitioned table and has both partition columns and a partition expression")]
77    PartitionedTableWithBothPartitionColumnsAndExpression(String),
78
79    #[error("Unsupported postgres version: {0}. Minimum supported version is 12")]
80    UnsupportedPostgresVersion(String),
81
82    #[error("Invalid response from postgres when checking version")]
83    InvalidPostgresVersionResponse,
84
85    #[error("Hypertable '{table_name}' dimension '{dimension_number}' does not have an interval")]
86    HypertableDimensionWithoutInterval {
87        table_name: String,
88        dimension_number: i64,
89    },
90
91    #[error("io error: `{0}`")]
92    IoError(#[from] std::io::Error),
93
94    #[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:?}")]
95    DataFormatsNotCompatible {
96        supported_by_target: Vec<DataFormat>,
97        supported_by_source: Vec<DataFormat>,
98        required_format: Option<DataFormat>,
99    },
100
101    #[error("join error: `{0}`")]
102    JoinError(#[from] tokio::task::JoinError),
103
104    #[error("Aggregate function '{0}' is missing transition type")]
105    AggregateFunctionMissingTransitionType(String),
106
107    #[error("Aggregate function '{0}' is missing transition function")]
108    AggregateFunctionMissingTransitionFunction(String),
109}
110
111/// A result type that uses the ElefantToolsError as the error type
112pub type Result<T = ()> = std::result::Result<T, ElefantToolsError>;