athena_rs 3.22.1

Hyper performant polyglot Database driver
Documentation
//! Snapshot-query SQL-error mapping for `/debug/schema`.
//!
//! This module maps low-level relation/column query SQL errors into the shared
//! snapshot error contract.

use super::debug_snapshot_error::LoggingSchemaSnapshotError;

/// Maps relation-query SQL errors into snapshot fetch error contracts.
pub(super) fn map_snapshot_relations_fetch_error(err: sqlx::Error) -> LoggingSchemaSnapshotError {
    LoggingSchemaSnapshotError::FetchRelations(err)
}

/// Maps column-query SQL errors into snapshot fetch error contracts.
pub(super) fn map_snapshot_columns_fetch_error(err: sqlx::Error) -> LoggingSchemaSnapshotError {
    LoggingSchemaSnapshotError::FetchColumns(err)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    /// Ensures relation-query SQL failures are wrapped in relation-fetch snapshot variants.
    fn mapper_wraps_relation_query_error() {
        let err = map_snapshot_relations_fetch_error(sqlx::Error::Protocol(
            "relations failed".to_string(),
        ));

        match err {
            LoggingSchemaSnapshotError::FetchRelations(_) => {}
            LoggingSchemaSnapshotError::FetchColumns(_) => {
                panic!("expected FetchRelations variant")
            }
        }
    }

    #[test]
    /// Ensures column-query SQL failures are wrapped in column-fetch snapshot variants.
    fn mapper_wraps_column_query_error() {
        let err =
            map_snapshot_columns_fetch_error(sqlx::Error::Protocol("columns failed".to_string()));

        match err {
            LoggingSchemaSnapshotError::FetchColumns(_) => {}
            LoggingSchemaSnapshotError::FetchRelations(_) => {
                panic!("expected FetchColumns variant")
            }
        }
    }
}