From 4b1ad126ad83cb59c00b26267a6ab170a5a16ef9 Mon Sep 17 00:00:00 2001 From: Sanpi Date: Wed, 15 Jan 2025 17:12:19 +0100 Subject: [PATCH] Improves error --- src/connection/_async.rs | 8 ++++---- src/connection/_copy.rs | 4 ++-- src/connection/_single_row_mode.rs | 2 +- src/connection/_status.rs | 2 +- src/pipeline.rs | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/connection/_async.rs b/src/connection/_async.rs index dc082a4..ae2d3fb 100644 --- a/src/connection/_async.rs +++ b/src/connection/_async.rs @@ -256,7 +256,7 @@ impl Connection { let status = unsafe { pq_sys::PQsetnonblocking(self.into(), non_blocking as i32) }; if status < 0 { - Err(crate::errors::Error::Unknow) + self.error() } else { Ok(()) } @@ -285,7 +285,7 @@ impl Connection { if status == 0 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + self.error() } } @@ -305,7 +305,7 @@ impl Connection { if status == 0 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + self.error() } } @@ -326,7 +326,7 @@ impl Connection { if status == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + self.error() } } } diff --git a/src/connection/_copy.rs b/src/connection/_copy.rs index 0aff1c2..775cad0 100644 --- a/src/connection/_copy.rs +++ b/src/connection/_copy.rs @@ -24,7 +24,7 @@ impl Connection { -1 => self.error(), 0 => Err(crate::errors::Error::Backend("Full buffers".to_string())), 1 => Ok(()), - _ => Err(crate::errors::Error::Unknow), + _ => self.error(), } } @@ -50,7 +50,7 @@ impl Connection { -1 => self.error(), 0 => Err(crate::errors::Error::Backend("Full buffers".to_string())), 1 => Ok(()), - _ => Err(crate::errors::Error::Unknow), + _ => self.error(), } } diff --git a/src/connection/_single_row_mode.rs b/src/connection/_single_row_mode.rs index b0c614f..26e0e7c 100644 --- a/src/connection/_single_row_mode.rs +++ b/src/connection/_single_row_mode.rs @@ -16,7 +16,7 @@ impl Connection { if success == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + self.error() } } diff --git a/src/connection/_status.rs b/src/connection/_status.rs index 5d00340..9b3c00c 100644 --- a/src/connection/_status.rs +++ b/src/connection/_status.rs @@ -169,7 +169,7 @@ impl Connection { let socket = unsafe { pq_sys::PQsocket(self.into()) }; if socket < 0 { - Err(crate::errors::Error::Unknow) + self.error() } else { Ok(socket) } diff --git a/src/pipeline.rs b/src/pipeline.rs index ace7fbe..01df7e7 100644 --- a/src/pipeline.rs +++ b/src/pipeline.rs @@ -37,7 +37,7 @@ pub fn enter(conn: &crate::Connection) -> crate::errors::Result { if success == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + conn.error() } } @@ -56,7 +56,7 @@ pub fn exit(conn: &crate::Connection) -> crate::errors::Result { if success == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + conn.error() } } @@ -85,7 +85,7 @@ pub fn sync(conn: &crate::Connection) -> crate::errors::Result { if success == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + conn.error() } } @@ -101,7 +101,7 @@ pub fn flush_request(conn: &crate::Connection) -> crate::errors::Result { if success == 1 { Ok(()) } else { - Err(crate::errors::Error::Unknow) + conn.error() } }