1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// use holochain_core_types::error::{RibosomeErrorCode, RibosomeReturnCode};
// use std::fmt;

/// Macro for creating a RibosomeErrorCode as a RuntimeValue Result-Option on the spot
/// Will panic! if out or memory or other serialization error occured.
#[macro_export]
macro_rules! zome_assert {
    ($stack:ident, $cond:expr) => {
        if !$cond {
            let error_report = ribosome_error_report!(format!(
                r#"Zome assertion failed: `{}`"#,
                stringify!($cond)
            ));
            let res = store_as_json(&mut $stack, error_report);
            return res.unwrap().encode();
        }
    };
}

/// Macro for creating a RibosomeErrorCode as a RuntimeValue Result-Option on the spot
#[macro_export]
macro_rules! ribosome_error_code {
    ($s:ident) => {
        Ok(Some(RuntimeValue::I32(
            ::holochain_wasm_utils::holochain_core_types::error::RibosomeErrorCode::$s as i32,
        )))
    };
}

/// Macro for creating a RibosomeErrorReport on the spot with file!() and line!()
#[macro_export]
macro_rules! ribosome_error_report {
    ($s:expr) => {
        ::holochain_wasm_utils::holochain_core_types::error::RibosomeErrorReport {
            description: $s.to_string(),
            file_name: file!().to_string(),
            line: line!().to_string(),
        }
    };
}