Skip to main content

duck_bail

Macro duck_bail 

Source
macro_rules! duck_bail {
    ($($arg:tt)*) => { ... };
}
Expand description

Returns early from a fallible user-defined-function body with a formatted error message.

Expands to return Err(format!(...).into()) — the surrounding function’s error type must implement From<String>, which is true for String itself and for Box<dyn std::error::Error + Send + Sync> (what #[duckdb_scalar]/ #[duckdb_table_function] route a Result<T, E> return through).

§Examples

use better_duck_core::duck_bail;

fn check(stop: i64, start: i64) -> Result<i64, String> {
    if stop < start {
        duck_bail!("stop ({stop}) must be >= start ({start})");
    }
    Ok(stop - start)
}
assert!(check(1, 10).is_err());