Skip to content

Commit

Permalink
fix: handle nullable values by printing NULL instead of panicking (#3686
Browse files Browse the repository at this point in the history
)
  • Loading branch information
joeydewaal authored Jan 16, 2025
1 parent 838a239 commit f6d2fa3
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions sqlx-core/src/type_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,17 @@ where

match T::decode(value.as_ref()) {
Ok(value) => Debug::fmt(&value, f),
Err(e) => f.write_fmt(format_args!(
"(error decoding SQL type {} as {}: {e:?})",
info.name(),
std::any::type_name::<T>()
)),
Err(e) => {
if e.is::<crate::error::UnexpectedNullError>() {
f.write_str("NULL")
} else {
f.write_fmt(format_args!(
"(error decoding SQL type {} as {}: {e:?})",
info.name(),
std::any::type_name::<T>()
))
}
}
}
},
}
Expand Down

0 comments on commit f6d2fa3

Please sign in to comment.