diff --git a/CHANGELOG.md b/CHANGELOG.md index f8e77c8226c..70f3810b957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Blocks of changes will separated by version increments. ## **[Unreleased]** +- [#834](https://github.com/wasmerio/wasmer/pull/834) Fix panic when unwraping `wasmer` arguments - [#833](https://github.com/wasmerio/wasmer/pull/833) Add doc example of using ImportObject's new `maybe_with_namespace` method - [#832](https://github.com/wasmerio/wasmer/pull/832) Delete unused runtime ABI - [#809](https://github.com/wasmerio/wasmer/pull/809) Fix bugs leading to panics in `LocalBacking`. diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index cbbea3b6b64..14d3caf2658 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -514,17 +514,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .instantiate(&import_object) .map_err(|e| format!("Can't instantiate loader module: {:?}", e))?; - let args: Vec = options - .args - .iter() - .map(|arg| arg.as_str()) - .map(|x| { - Value::I32(x.parse().expect(&format!( + let mut args: Vec = Vec::new(); + for arg in options.args.iter() { + let x = arg.as_str().parse().map_err(|_| { + format!( "Can't parse the provided argument {:?} as a integer", - x - ))) - }) - .collect(); + arg.as_str() + ) + })?; + args.push(Value::I32(x)); + } + let index = instance .resolve_func("_start") .expect("The loader requires a _start function to be present in the module"); @@ -658,12 +658,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> { .instantiate(&import_object) .map_err(|e| format!("Can't instantiate module: {:?}", e))?; - let args: Vec = options - .args - .iter() - .map(|arg| arg.as_str()) - .map(|x| Value::I32(x.parse().unwrap())) - .collect(); + let mut args: Vec = Vec::new(); + for arg in options.args.iter() { + let x = arg.as_str().parse().map_err(|_| { + format!( + "Can't parse the provided argument {:?} as a integer", + arg.as_str() + ) + })?; + args.push(Value::I32(x)); + } + instance .dyn_func("main") .map_err(|e| format!("{:?}", e))?