Skip to content

Commit

Permalink
Merge #858
Browse files Browse the repository at this point in the history
858: [fix 857] panic when target module don't have exported _start function r=syrusakbary a=pventuzelo

# Description

Fix #857 
* replace `expect` by `map_err` for `loader`
* replace `expect` by `map_err` in other part of `wasmer.rs`

# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Patrick Ventuzelo <[email protected]>
Co-authored-by: Patrick Ventuzelo <[email protected]>
  • Loading branch information
3 people authored Dec 11, 2019
2 parents ca03402 + 3836b54 commit 18318c2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## **[Unreleased]**

- [#858](https://github.com/wasmerio/wasmer/pull/858) Minor panic fix when wasmer binary with `loader` option run a module without exported `_start` function.
- [#1056](https://github.com/wasmerio/wasmer/pull/1056) Improved `--invoke` args parsing (supporting `i32`, `i64`, `f32` and `f32`) in Wasmer CLI
- [#1054](https://github.com/wasmerio/wasmer/pull/1054) Improve `--invoke` output in Wasmer CLI
- [#1053](https://github.com/wasmerio/wasmer/pull/1053) For RuntimeError and breakpoints, use Box<Any + Send> instead of Box<Any>.
Expand Down
13 changes: 7 additions & 6 deletions src/bin/wasmer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ fn execute_wasi(
f.read_to_end(&mut out).unwrap();
Some(
wasmer_runtime_core::state::InstanceImage::from_bytes(&out)
.expect("failed to decode image"),
.map_err(|_| format!("failed to decode image"))?,
)
} else {
None
Expand Down Expand Up @@ -751,20 +751,21 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
args.push(Value::I32(x));
}

let index = instance
.resolve_func("_start")
.expect("The loader requires a _start function to be present in the module");
let index = instance.resolve_func("_start").map_err(|_| {
format!("The loader requires a _start function to be present in the module")
})?;

let mut ins: Box<dyn LoadedInstance<Error = String>> = match loader {
LoaderName::Local => Box::new(
instance
.load(LocalLoader)
.expect("Can't use the local loader"),
.map_err(|e| format!("Can't use the local loader: {:?}", e))?,
),
#[cfg(feature = "loader-kernel")]
LoaderName::Kernel => Box::new(
instance
.load(::wasmer_kernel_loader::KernelLoader)
.expect("Can't use the kernel loader"),
.map_err(|e| format!("Can't use the local loader: {:?}", e))?,
),
};
println!("{:?}", ins.call(index, &args));
Expand Down

0 comments on commit 18318c2

Please sign in to comment.