headless_lms_utils/error/mod.rs
1/*!
2Error utilities and the error and result types for all the util functions.
3*/
4
5pub mod util_error;
6
7#[macro_use]
8pub mod macros;
9
10/// True when anything in `error`'s cause chain is a `sqlx::Error::Io`: usually the database being
11/// reset under a local development cluster, and the cue to reacquire a connection held across ticks.
12pub fn is_db_disconnect(error: &(dyn std::error::Error + 'static)) -> bool {
13 std::iter::successors(Some(error), |error| error.source()).any(|error| {
14 matches!(
15 error.downcast_ref::<sqlx::Error>(),
16 Some(sqlx::Error::Io(..))
17 )
18 })
19}