multiversx_chain_vm/vm_hooks/vh_handler/
vh_error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use multiversx_chain_core::types::ReturnCode;

use crate::{types::RawHandle, vm_hooks::VMHooksHandlerSource};

use super::VMHooksManagedTypes;

pub trait VMHooksError: VMHooksHandlerSource {
    fn signal_error(&self, message: &[u8]) -> ! {
        // can sometimes help in tests
        // run `clear & cargo test -- --nocapture` to see the output
        println!("{}", std::str::from_utf8(message).unwrap());

        self.halt_with_error(ReturnCode::UserError, std::str::from_utf8(message).unwrap())
    }
}

pub trait VMHooksErrorManaged: VMHooksManagedTypes + VMHooksError {
    fn signal_error_from_buffer(&self, message_handle: RawHandle) -> ! {
        self.signal_error(self.m_types_lock().mb_get(message_handle))
    }
}