Skip to content

Commit f6d2fa3

Browse files
authored
fix: handle nullable values by printing NULL instead of panicking (#3686)
1 parent 838a239 commit f6d2fa3

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

sqlx-core/src/type_checking.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,17 @@ where
7272

7373
match T::decode(value.as_ref()) {
7474
Ok(value) => Debug::fmt(&value, f),
75-
Err(e) => f.write_fmt(format_args!(
76-
"(error decoding SQL type {} as {}: {e:?})",
77-
info.name(),
78-
std::any::type_name::<T>()
79-
)),
75+
Err(e) => {
76+
if e.is::<crate::error::UnexpectedNullError>() {
77+
f.write_str("NULL")
78+
} else {
79+
f.write_fmt(format_args!(
80+
"(error decoding SQL type {} as {}: {e:?})",
81+
info.name(),
82+
std::any::type_name::<T>()
83+
))
84+
}
85+
}
8086
}
8187
},
8288
}

0 commit comments

Comments
 (0)