From f6d2fa3a3de1d888f4e36096dd56a3f5e0c95771 Mon Sep 17 00:00:00 2001 From: joeydewaal <99046430+joeydewaal@users.noreply.github.com> Date: Thu, 16 Jan 2025 02:08:16 +0100 Subject: [PATCH] fix: handle nullable values by printing NULL instead of panicking (#3686) --- sqlx-core/src/type_checking.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sqlx-core/src/type_checking.rs b/sqlx-core/src/type_checking.rs index 384d15f4..57661245 100644 --- a/sqlx-core/src/type_checking.rs +++ b/sqlx-core/src/type_checking.rs @@ -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::() - )), + Err(e) => { + if e.is::() { + f.write_str("NULL") + } else { + f.write_fmt(format_args!( + "(error decoding SQL type {} as {}: {e:?})", + info.name(), + std::any::type_name::() + )) + } + } } }, }