use gear_core::{ids::ActorId, pages::WasmPage};
use gear_core_errors::ExtError;
use parity_scale_codec::Error as CodecError;
pub type Result<T, E = TestError> = core::result::Result<T, E>;
#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
pub enum TestError {
#[error("Invalid return type after execution")]
InvalidReturnType,
#[error("Function not found in executor: `{0}`")]
FunctionNotFound(String),
#[error("Actor not found: `{0}`")]
ActorNotFound(ActorId),
#[error("Actor is not executable: `{0}`")]
ActorIsNotExecutable(ActorId),
#[error("Meta WASM binary hasn't been provided")]
MetaBinaryNotProvided,
#[error("Insufficient memory: available {0:?} < requested {1:?}")]
InsufficientMemory(WasmPage, WasmPage),
#[error("Invalid import module: `{0}` instead of `env`")]
InvalidImportModule(String),
#[error("Failed to call unsupported function: `{0}`")]
UnsupportedFunction(String),
#[error("Execution error: `{0}`")]
ExecutionError(#[from] ExtError),
#[error("Memory error: `{0}`")]
MemoryError(#[from] gear_core_errors::MemoryError),
#[error("Codec error: `{0}`")]
ScaleCodecError(#[from] CodecError),
#[error("Instrumentation of binary code failed.")]
Instrumentation,
#[error("Reading of program state failed: `{0}`")]
ReadStateError(String),
#[error("Reading of program state failed: `{0}`")]
GbuildArtifactNotFound(String),
}
macro_rules! usage_panic {
($($arg:tt)*) => {{
use colored::Colorize as _;
let panic_msg = format!($($arg)*).red().bold();
panic!("{}", panic_msg);
}};
}
pub(crate) use usage_panic;