Skip to content

Commit

Permalink
chore(postgres): include nullables query in error
Browse files Browse the repository at this point in the history
  • Loading branch information
abonander committed Aug 21, 2024
1 parent d3e75e7 commit 8db2055
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
17 changes: 11 additions & 6 deletions sqlx-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,16 @@ impl From<crate::migrate::MigrateError> 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!(),
)
)
};
}
8 changes: 7 additions & 1 deletion sqlx-postgres/src/connection/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,13 @@ WHERE rngtypid = $1
let mut nullables: Vec<Option<bool>> = 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")
Expand Down
2 changes: 1 addition & 1 deletion sqlx-postgres/src/io/buf_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl PgBufMutExt for Vec<u8> {
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 {
Expand Down

0 comments on commit 8db2055

Please sign in to comment.