Skip to main content

multiversx_sc_scenario/executor/debug/
contract_debug_executor_err.rs

1use std::{error::Error, fmt};
2
3#[derive(Debug)]
4pub struct ContractDebugExecutorNotRegisteredError(String);
5
6impl ContractDebugExecutorNotRegisteredError {
7    pub fn new(contract_identifier: &[u8]) -> Self {
8        ContractDebugExecutorNotRegisteredError(format_error_message(contract_identifier))
9    }
10}
11
12fn format_error_message(contract_identifier: &[u8]) -> String {
13    if let Ok(s) = std::str::from_utf8(contract_identifier) {
14        format!("Unknown contract: {s}")
15    } else {
16        format!(
17            "Unknown contract of length {} bytes",
18            contract_identifier.len()
19        )
20    }
21}
22
23impl fmt::Display for ContractDebugExecutorNotRegisteredError {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        self.0.fmt(f)
26    }
27}
28
29impl Error for ContractDebugExecutorNotRegisteredError {}