Improve formatting of error messages we display from wabt

This commit is contained in:
Mark McCaskey 2020-01-06 15:30:30 -05:00
parent d408831ed6
commit d3d720babd
2 changed files with 46 additions and 5 deletions

32
Cargo.lock generated
View File

@ -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",

View File

@ -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<dyn Compiler> = get_compiler_by_backend(options.backend, options)