fix: handle nullable values by printing NULL instead of panicking (#3686)

This commit is contained in:
joeydewaal 2025-01-16 02:08:16 +01:00 committed by GitHub
parent 838a239a2c
commit f6d2fa3a3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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>()
))
}
}
}
},
}