From 8db2055ed88c2ccfe461143d8cc143832a7bfde9 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Wed, 21 Aug 2024 13:50:48 -0700 Subject: [PATCH] chore(postgres): include nullables query in error --- sqlx-core/src/error.rs | 17 +++++++++++------ sqlx-postgres/src/connection/describe.rs | 8 +++++++- sqlx-postgres/src/io/buf_mut.rs | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index 042342ef9f..17774addd2 100644 --- a/sqlx-core/src/error.rs +++ b/sqlx-core/src/error.rs @@ -312,11 +312,16 @@ impl From for Error { /// Format an error message as a `Protocol` error #[macro_export] macro_rules! err_protocol { - ($expr:expr) => { - $crate::error::Error::Protocol($expr.into()) - }; - - ($fmt:expr, $($arg:tt)*) => { - $crate::error::Error::Protocol(format!($fmt, $($arg)*)) + ($($fmt_args:tt)*) => { + $crate::error::Error::Protocol( + format!( + "{} ({}:{})", + // Note: the format string needs to be unmodified (e.g. by `concat!()`) + // for implicit formatting arguments to work + format_args!($($fmt_args)*), + module_path!(), + line!(), + ) + ) }; } diff --git a/sqlx-postgres/src/connection/describe.rs b/sqlx-postgres/src/connection/describe.rs index d9c55201a0..9d532a5178 100644 --- a/sqlx-postgres/src/connection/describe.rs +++ b/sqlx-postgres/src/connection/describe.rs @@ -466,7 +466,13 @@ WHERE rngtypid = $1 let mut nullables: Vec> = nullable_query .build_query_scalar() .fetch_all(&mut *self) - .await?; + .await + .map_err(|e| { + err_protocol!( + "error from nullables query: {e}; query: {:?}", + nullable_query.sql() + ) + })?; // If the server is CockroachDB or Materialize, skip this step (#1248). if !self.stream.parameter_statuses.contains_key("crdb_version") diff --git a/sqlx-postgres/src/io/buf_mut.rs b/sqlx-postgres/src/io/buf_mut.rs index ff6fe03df3..eea9d34acd 100644 --- a/sqlx-postgres/src/io/buf_mut.rs +++ b/sqlx-postgres/src/io/buf_mut.rs @@ -27,7 +27,7 @@ impl PgBufMutExt for Vec { let size_result = write_result.and_then(|_| { let size = self.len() - offset; i32::try_from(size) - .map_err(|_| err_protocol!("message size out of range for Pg protocol: {size")) + .map_err(|_| err_protocol!("message size out of range for protocol: {size}")) }); match size_result {