diff --git a/core/src/doc/compute.rs b/core/src/doc/compute.rs index b2a83c2c..aa56ff01 100644 --- a/core/src/doc/compute.rs +++ b/core/src/doc/compute.rs @@ -88,7 +88,7 @@ impl Document { // two separtate UNIQUE index definitions, and it // wasn't possible to detect which record was the // correct one to be updated - let _ = chn.send(Err(Error::Unreachable("Internal error"))).await; + let _ = chn.send(Err(fail!("Internal error"))).await; // Break the loop Ok(()) } diff --git a/core/src/doc/process.rs b/core/src/doc/process.rs index 0f91ca1f..7a164205 100644 --- a/core/src/doc/process.rs +++ b/core/src/doc/process.rs @@ -80,6 +80,6 @@ impl Document { // two separtate UNIQUE index definitions, and it // wasn't possible to detect which record was the // correct one to be updated - Err(Error::Unreachable("Internal error")) + Err(fail!("Internal error")) } } diff --git a/core/src/mac/mod.rs b/core/src/mac/mod.rs index 146ca0b4..33d50e9b 100644 --- a/core/src/mac/mod.rs +++ b/core/src/mac/mod.rs @@ -1,3 +1,10 @@ +/// Throws an unreachable error with location details +macro_rules! fail { + ($msg: literal) => { + $crate::err::Error::Unreachable(concat!(file!(), ":", line!(), ": ", $msg)) + }; +} + /// Converts some text into a new line byte string macro_rules! bytes { ($expression:expr) => { @@ -203,6 +210,8 @@ macro_rules! async_defer{ #[cfg(test)] mod test { + use crate::err::Error; + #[tokio::test] async fn async_defer_basic() { let mut counter = 0; @@ -241,4 +250,12 @@ mod test { }) .await; } + + #[test] + fn fail() { + let Error::Unreachable(msg) = fail!("Reached unreachable code") else { + panic!() + }; + assert_eq!("core/src/mac/mod.rs:256: Reached unreachable code", msg); + } }