Add fail!()
macro and test (#4699)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
bb1884d56b
commit
5da3a642a2
3 changed files with 19 additions and 2 deletions
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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"))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue