Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix unwrap error when given a no export functions wasm #2386

Merged
merged 2 commits into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,17 @@ impl Run {
let suggested_command = format!(
"wasmer {} -i {} {}",
self.path.display(),
suggested_functions.get(0).unwrap(),
suggested_functions.get(0).unwrap_or(&String::new()),
args.join(" ")
);
let suggestion = format!(
"Similar functions found: {}.\nTry with: {}",
names, suggested_command
);
let suggestion = if suggested_functions.len() == 0 {
String::from("Can not find any export functions.")
} else {
format!(
"Similar functions found: {}.\nTry with: {}",
names, suggested_command
)
};
match e {
ExportError::Missing(_) => {
anyhow!("No export `{}` found in the module.\n{}", name, suggestion)
Expand Down
5 changes: 5 additions & 0 deletions tests/examples/no_start.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(module
(type (;0;) (func (param f64) (result i32)))
(func (;0;) (type 0) (param f64) (result i32)
unreachable))

4 changes: 4 additions & 0 deletions tests/integration/cli/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub const ASSET_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../test

pub const WASMER_INCLUDE_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../lib/c-api");

#[cfg(feature = "debug")]
pub const WASMER_PATH: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../../target/debug/wasmer");

#[cfg(not(feature = "debug"))]
pub const WASMER_PATH: &str = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../../target/release/wasmer"
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ fn test_no_imports_wat_path() -> String {
format!("{}/{}", ASSET_PATH, "fib.wat")
}

fn test_no_start_wat_path() -> String {
format!("{}/{}", ASSET_PATH, "no_start.wat")
}

#[test]
fn run_wasi_works() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
Expand Down Expand Up @@ -39,6 +43,7 @@ fn run_wasi_works() -> anyhow::Result<()> {
}

#[test]

fn run_no_imports_wasm_works() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
.arg("run")
Expand All @@ -57,3 +62,16 @@ fn run_no_imports_wasm_works() -> anyhow::Result<()> {

Ok(())
}

#[test]
fn run_no_start_wasm_report_error() -> anyhow::Result<()> {
let output = Command::new(WASMER_PATH)
.arg("run")
.arg(test_no_start_wat_path())
.output()?;

assert_eq!(output.status.success(), false);
let result = std::str::from_utf8(&output.stderr).unwrap().to_string();
assert_eq!(result.contains("Can not find any export functions."), true);
Ok(())
}