use crate::js::lib::std::string::String;
#[cfg(feature = "std")]
use thiserror::Error;
#[derive(Debug)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum CompileError {
#[cfg_attr(feature = "std", error("WebAssembly translation error: {0}"))]
Wasm(WasmError),
#[cfg_attr(feature = "std", error("Compilation error: {0}"))]
Codegen(String),
#[cfg_attr(feature = "std", error("Validation error: {0}"))]
Validate(String),
#[cfg_attr(feature = "std", error("Feature {0} is not yet supported"))]
UnsupportedFeature(String),
#[cfg_attr(feature = "std", error("The target {0} is not yet supported (see https://docs.wasmer.io/ecosystem/wasmer/wasmer-features)"))]
UnsupportedTarget(String),
#[cfg_attr(feature = "std", error("Insufficient resources: {0}"))]
Resource(String),
}
#[cfg(feature = "core")]
impl std::fmt::Display for CompileError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CompileError")
}
}
impl From<WasmError> for CompileError {
fn from(original: WasmError) -> Self {
Self::Wasm(original)
}
}
#[derive(Debug)]
#[cfg_attr(feature = "std", derive(Error))]
pub enum WasmError {
#[cfg_attr(
feature = "std",
error("Invalid input WebAssembly code at offset {offset}: {message}")
)]
InvalidWebAssembly {
message: String,
offset: usize,
},
#[cfg_attr(feature = "std", error("Unsupported feature: {0}"))]
Unsupported(String),
#[cfg_attr(feature = "std", error("{0}"))]
Generic(String),
}