diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index 042342ef..17774add 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 d9c55201..9d532a51 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 ff6fe03d..eea9d34a 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 {