mirror of
https://github.com/fluencelabs/interface-types
synced 2024-12-04 07:10:21 +00:00
feat!: propagate errors from module calls (#42)
* compiling * prepare for merge
This commit is contained in:
parent
44ca83c001
commit
354539f5cb
8
Cargo.lock
generated
8
Cargo.lock
generated
@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.75"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
@ -29,6 +35,7 @@ dependencies = [
|
||||
name = "it-lilo"
|
||||
version = "0.5.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"fluence-it-types",
|
||||
"it-memory-traits",
|
||||
"log",
|
||||
@ -223,6 +230,7 @@ dependencies = [
|
||||
name = "wasmer-interface-types-fl"
|
||||
version = "0.26.1"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"fluence-it-types",
|
||||
"it-lilo",
|
||||
"it-memory-traits",
|
||||
|
@ -14,6 +14,7 @@ path = "src/lib.rs"
|
||||
fluence-it-types = { path = "../it-types/", version = "0.4.1" }
|
||||
it-memory-traits = { path = "../it-memory-traits", version = "0.4.0" }
|
||||
|
||||
anyhow = "1.0.75"
|
||||
paste = "1.0.11"
|
||||
thiserror = "1.0.38"
|
||||
log = "0.4.17"
|
||||
|
@ -45,8 +45,12 @@ pub enum AllocatableError {
|
||||
},
|
||||
|
||||
/// Failed to call a allocate function.
|
||||
#[error("call to allocated was failed")]
|
||||
AllocateCallFailed,
|
||||
#[error(r#"call to allocate function was failed: {reason}"#)]
|
||||
AllocateCallFailed {
|
||||
/// error returned by the allocate function
|
||||
#[source]
|
||||
reason: anyhow::Error,
|
||||
},
|
||||
|
||||
/// Allocate input types doesn't match with needed.
|
||||
#[error(
|
||||
|
@ -13,6 +13,7 @@ it-to-bytes = { path = "../crates/to-bytes", version = "0.1.0" }
|
||||
it-lilo = { path = "../crates/it-lilo", version = "0.5.1" }
|
||||
it-memory-traits = { path = "../crates/it-memory-traits", version = "0.4.0" }
|
||||
|
||||
anyhow = "1.0.75"
|
||||
nom = "7.1"
|
||||
# do not update wast, new versions expect different wit syntax
|
||||
wast = "8.0"
|
||||
|
@ -172,10 +172,14 @@ pub enum InstructionErrorKind {
|
||||
},
|
||||
|
||||
/// Failed to call a local or import function.
|
||||
#[error("failed while calling the local or import function `{function_name}`")]
|
||||
#[error("failed while calling the local or import function `{function_name}`: {reason}")]
|
||||
LocalOrImportCall {
|
||||
/// The local or import function name that has been called.
|
||||
function_name: String,
|
||||
|
||||
/// Error returned by the local or import call
|
||||
#[source]
|
||||
reason: anyhow::Error,
|
||||
},
|
||||
|
||||
/// The memory doesn't exist.
|
||||
|
@ -34,11 +34,12 @@ executable_instruction!(
|
||||
|
||||
log::debug!("call-core: calling {} with arguments: {:?}", local_or_import.name(), inputs);
|
||||
|
||||
let outputs = local_or_import.call(runtime.store, &inputs).map_err(|_| {
|
||||
let outputs = local_or_import.call(runtime.store, &inputs).map_err(|e| {
|
||||
InstructionError::from_error_kind(
|
||||
instruction.clone(),
|
||||
InstructionErrorKind::LocalOrImportCall {
|
||||
function_name: local_or_import.name().to_string(),
|
||||
reason: e
|
||||
},
|
||||
)
|
||||
})?;
|
||||
|
@ -87,7 +87,7 @@ where
|
||||
|
||||
let outcome = local_or_import
|
||||
.call(store, &inputs)
|
||||
.map_err(|_| AllocateCallFailed)?;
|
||||
.map_err(|e| AllocateCallFailed { reason: e })?;
|
||||
|
||||
if outcome.len() != 1 {
|
||||
return Err(AllocateFuncIncompatibleOutput);
|
||||
|
@ -51,7 +51,7 @@ pub trait Export {
|
||||
fn outputs_cardinality(&self) -> usize;
|
||||
fn arguments(&self) -> &[FunctionArg];
|
||||
fn outputs(&self) -> &[IType];
|
||||
fn call(&self, arguments: &[IValue]) -> Result<Vec<IValue>, ()>;
|
||||
fn call(&self, arguments: &[IValue]) -> Result<Vec<IValue>, anyhow::Error>;
|
||||
}
|
||||
|
||||
pub trait LocalImport<Store: self::Store> {
|
||||
@ -64,7 +64,7 @@ pub trait LocalImport<Store: self::Store> {
|
||||
&self,
|
||||
store: &mut <Store as self::Store>::ActualStore<'_>,
|
||||
arguments: &[IValue],
|
||||
) -> Result<Vec<IValue>, ()>;
|
||||
) -> Result<Vec<IValue>, anyhow::Error>;
|
||||
}
|
||||
|
||||
pub use it_memory_traits::Store;
|
||||
@ -105,8 +105,8 @@ impl Export for () {
|
||||
&[]
|
||||
}
|
||||
|
||||
fn call(&self, _arguments: &[IValue]) -> Result<Vec<IValue>, ()> {
|
||||
Err(())
|
||||
fn call(&self, _arguments: &[IValue]) -> Result<Vec<IValue>, anyhow::Error> {
|
||||
Err(anyhow::anyhow!("some error"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,8 +135,8 @@ impl<Store: self::Store> LocalImport<Store> for () {
|
||||
&self,
|
||||
_store: &mut <Store as self::Store>::ActualStore<'_>,
|
||||
_arguments: &[IValue],
|
||||
) -> Result<Vec<IValue>, ()> {
|
||||
Err(())
|
||||
) -> Result<Vec<IValue>, anyhow::Error> {
|
||||
Err(anyhow::anyhow!("some error"))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user