Skip to main content

entelix_graphmemory_pg/
error.rs

1//! Local error type for `PgGraphMemory`. Surfaces to callers as
2//! `entelix_core::Error` when crossing the public `GraphMemory`
3//! boundary.
4
5use thiserror::Error;
6
7use entelix_core::error::Error;
8
9/// Result alias used inside `entelix-graphmemory-pg`.
10pub type PgGraphMemoryResult<T> = std::result::Result<T, PgGraphMemoryError>;
11
12/// Errors that can surface from `PgGraphMemory`.
13#[derive(Debug, Error)]
14#[non_exhaustive]
15pub enum PgGraphMemoryError {
16    /// Underlying `sqlx` / Postgres failure.
17    #[error("postgres transport failure: {0}")]
18    Sqlx(#[from] sqlx::Error),
19
20    /// Server returned a row shape inconsistent with what the schema
21    /// migration installed. Indicates either a stale
22    /// `auto_migrate=false` deployment or external schema drift.
23    #[error("malformed row shape: {0}")]
24    Malformed(String),
25
26    /// Configuration error — invalid connection string, missing
27    /// pool / pool URL, unsafe table name.
28    #[error("configuration error: {0}")]
29    Config(String),
30
31    /// JSON encode / decode failure on a node / edge payload.
32    #[error("payload codec failure: {0}")]
33    Codec(#[from] serde_json::Error),
34}
35
36impl From<PgGraphMemoryError> for Error {
37    fn from(err: PgGraphMemoryError) -> Self {
38        match err {
39            PgGraphMemoryError::Config(msg) => Self::config(msg),
40            PgGraphMemoryError::Codec(e) => Self::Serde(e),
41            other => Self::provider_network_from(other),
42        }
43    }
44}