Skip to content

Commit d93a20e

Browse files
committed
chore(postgres): include nullables query in error
1 parent d3e75e7 commit d93a20e

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

sqlx-core/src/error.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,16 @@ impl From<crate::migrate::MigrateError> for Error {
312312
/// Format an error message as a `Protocol` error
313313
#[macro_export]
314314
macro_rules! err_protocol {
315-
($expr:expr) => {
316-
$crate::error::Error::Protocol($expr.into())
317-
};
318-
319-
($fmt:expr, $($arg:tt)*) => {
320-
$crate::error::Error::Protocol(format!($fmt, $($arg)*))
315+
($($fmt_args:tt)*) => {
316+
$crate::error::Error::Protocol(
317+
format!(
318+
"{} ({}:{})",
319+
// Note: the format string needs to be unmodified (e.g. by `concat!()`)
320+
// for implicit formatting arguments to work
321+
format_args!($($fmt_args)*),
322+
module_path!(),
323+
line!(),
324+
)
325+
)
321326
};
322327
}

sqlx-postgres/src/connection/describe.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,13 @@ WHERE rngtypid = $1
466466
let mut nullables: Vec<Option<bool>> = nullable_query
467467
.build_query_scalar()
468468
.fetch_all(&mut *self)
469-
.await?;
469+
.await
470+
.map_err(|e| {
471+
err_protocol!(
472+
"error from nullables query: {e}; query: {:?}",
473+
nullable_query.sql()
474+
)
475+
})?;
470476

471477
// If the server is CockroachDB or Materialize, skip this step (#1248).
472478
if !self.stream.parameter_statuses.contains_key("crdb_version")

0 commit comments

Comments
 (0)