klieo_memory_pgvector/
error.rs1use klieo_core::error::MemoryError;
4
5const UNDEFINED_TABLE: &str = "42P01";
8
9pub(crate) fn store_err(e: sqlx::Error) -> MemoryError {
10 MemoryError::Store(e.to_string())
11}
12
13pub(crate) fn is_undefined_table(e: &sqlx::Error) -> bool {
19 matches!(e, sqlx::Error::Database(db) if db.code().as_deref() == Some(UNDEFINED_TABLE))
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn store_err_routes_to_store_variant() {
28 let mem = store_err(sqlx::Error::PoolClosed);
29 assert!(matches!(mem, MemoryError::Store(_)));
30 }
31
32 #[test]
33 fn non_database_error_is_not_undefined_table() {
34 assert!(!is_undefined_table(&sqlx::Error::PoolClosed));
35 }
36}