fix unwrap by handling parse error

This commit is contained in:
Patrick Ventuzelo 2019-09-25 21:52:45 +02:00
parent 7bf306eb27
commit 5b3333c6f5

View File

@ -514,17 +514,17 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
.instantiate(&import_object) .instantiate(&import_object)
.map_err(|e| format!("Can't instantiate loader module: {:?}", e))?; .map_err(|e| format!("Can't instantiate loader module: {:?}", e))?;
let args: Vec<Value> = options let mut args: Vec<Value> = Vec::new();
.args for arg in options.args.iter() {
.iter() let x = arg.as_str().parse().map_err(|_| {
.map(|arg| arg.as_str()) format!(
.map(|x| {
Value::I32(x.parse().expect(&format!(
"Can't parse the provided argument {:?} as a integer", "Can't parse the provided argument {:?} as a integer",
x arg.as_str()
))) )
}) })?;
.collect(); args.push(Value::I32(x));
}
let index = instance let index = instance
.resolve_func("_start") .resolve_func("_start")
.expect("The loader requires a _start function to be present in the module"); .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) .instantiate(&import_object)
.map_err(|e| format!("Can't instantiate module: {:?}", e))?; .map_err(|e| format!("Can't instantiate module: {:?}", e))?;
let args: Vec<Value> = options let mut args: Vec<Value> = Vec::new();
.args for arg in options.args.iter() {
.iter() let x = arg.as_str().parse().map_err(|_| {
.map(|arg| arg.as_str()) format!(
.map(|x| Value::I32(x.parse().unwrap())) "Can't parse the provided argument {:?} as a integer",
.collect(); arg.as_str()
)
})?;
args.push(Value::I32(x));
}
instance instance
.dyn_func("main") .dyn_func("main")
.map_err(|e| format!("{:?}", e))? .map_err(|e| format!("{:?}", e))?