From d3d720babd6f3d59922457dda5935da64dd2fe4c Mon Sep 17 00:00:00 2001 From: Mark McCaskey Date: Mon, 6 Jan 2020 15:30:30 -0500 Subject: [PATCH] Improve formatting of error messages we display from wabt --- Cargo.lock | 32 +++++++++++++++++++++++++++++--- src/bin/wasmer.rs | 19 +++++++++++++++++-- 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bcbe7400d..0f5d6d7c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -558,7 +558,7 @@ dependencies = [ "libc", "llvm-sys", "once_cell", - "parking_lot", + "parking_lot 0.10.0", "regex", ] @@ -827,6 +827,17 @@ dependencies = [ "md5", ] +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" +dependencies = [ + "lock_api", + "parking_lot_core 0.6.2", + "rustc_version", +] + [[package]] name = "parking_lot" version = "0.10.0" @@ -834,7 +845,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92e98c49ab0b7ce5b222f2cc9193fc4efe11c6d0bd4f648e374684a6857b1cfc" dependencies = [ "lock_api", - "parking_lot_core", + "parking_lot_core 0.7.0", +] + +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" +dependencies = [ + "cfg-if", + "cloudabi", + "libc", + "redox_syscall", + "rustc_version", + "smallvec 0.6.13", + "winapi", ] [[package]] @@ -1761,7 +1787,7 @@ dependencies = [ "libc", "nix", "page_size", - "parking_lot", + "parking_lot 0.9.0", "rustc_version", "serde", "serde-bench", diff --git a/src/bin/wasmer.rs b/src/bin/wasmer.rs index 1c19e6082..04ef6d3a2 100644 --- a/src/bin/wasmer.rs +++ b/src/bin/wasmer.rs @@ -11,6 +11,7 @@ extern crate structopt; use std::collections::HashMap; use std::env; +use std::error::Error; use std::fs::{metadata, read_to_string, File}; use std::io; use std::io::Read; @@ -623,8 +624,22 @@ fn execute_wasm(options: &Run) -> Result<(), String> { if !utils::is_wasm_binary(&wasm_binary) { let features = options.features.into_wabt_features(); - wasm_binary = wabt::wat2wasm_with_features(wasm_binary, features) - .map_err(|e| format!("Can't convert from wast to wasm: {:?}", e))?; + wasm_binary = wabt::wat2wasm_with_features(wasm_binary, features).map_err(|e| { + format!( + "Can't convert from wast to wasm because \"{}\"{}", + e.description(), + match e.kind() { + wabt::ErrorKind::Deserialize(s) + | wabt::ErrorKind::Parse(s) + | wabt::ErrorKind::ResolveNames(s) + | wabt::ErrorKind::Validate(s) => format!(":\n\n{}", s), + wabt::ErrorKind::Nul + | wabt::ErrorKind::WriteText + | wabt::ErrorKind::NonUtf8Result + | wabt::ErrorKind::WriteBinary => "".to_string(), + } + ) + })?; } let compiler: Box = get_compiler_by_backend(options.backend, options)