Skip to main content

pgevolve_core/catalog/
error.rs

1//! Errors raised by the catalog reader.
2
3use thiserror::Error;
4
5use crate::catalog::CatalogQuery;
6use crate::ir::IrError;
7use crate::parse::ParseError;
8
9/// Errors raised by the catalog reader.
10#[derive(Debug, Error)]
11pub enum CatalogError {
12    /// The querier returned an error.
13    #[error("catalog query {query:?} failed: {message}")]
14    QueryFailed {
15        /// Which query failed.
16        query: CatalogQuery,
17        /// Adapter-supplied message.
18        message: String,
19    },
20
21    /// The querier returned no rows for a query that requires at least one.
22    #[error("catalog query {query:?} returned no rows")]
23    MissingResult {
24        /// Which query produced the empty result.
25        query: CatalogQuery,
26    },
27
28    /// A column expected on a [`crate::catalog::rows::Row`] was missing.
29    #[error("catalog row missing column {column:?} for query {query:?}")]
30    MissingColumn {
31        /// Which query produced the row.
32        query: CatalogQuery,
33        /// Column name.
34        column: String,
35    },
36
37    /// A column had an unexpected SQL type.
38    #[error("catalog row column {column:?} had unexpected type for query {query:?}: {message}")]
39    BadColumnType {
40        /// Which query produced the row.
41        query: CatalogQuery,
42        /// Column name.
43        column: String,
44        /// Description of the mismatch.
45        message: String,
46    },
47
48    /// Postgres reported a major version we do not (yet) support.
49    #[error("unsupported Postgres major version: {0} (supported: 14, 15, 16, 17)")]
50    UnsupportedPgVersion(u32),
51
52    /// The configured managed-schema list named a reserved schema we never manage.
53    #[error("schema {0:?} is reserved and cannot be managed by pgevolve")]
54    CannotManageReservedSchema(String),
55
56    /// A configured ignore glob was syntactically invalid.
57    #[error("invalid ignore glob {0:?}: {1}")]
58    InvalidIgnoreGlob(String, glob::PatternError),
59
60    /// IR construction failed while assembling rows into [`crate::ir::catalog::Catalog`].
61    #[error("IR error while assembling catalog: {0}")]
62    Ir(#[from] IrError),
63
64    /// A `pg_get_constraintdef`/`pg_get_indexdef`/default expression failed to parse.
65    #[error("re-parsing introspected SQL fragment failed: {0}")]
66    ReparseFailed(#[from] Box<ParseError>),
67
68    /// A catalog row referenced an object oid that no other query produced.
69    #[error("catalog assembly: dangling reference {kind} for {what}")]
70    DanglingReference {
71        /// What kind of reference (e.g., "table for column").
72        kind: &'static str,
73        /// Identifier or oid of the missing object.
74        what: String,
75    },
76}