Skip to content

Commit 8e6ac75

Browse files
refactor: use wasmtime::error::Context pervasively
1 parent 48349c5 commit 8e6ac75

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ anyhow = { workspace = true, optional = true }
2323
clap = { workspace = true, optional = true, features = ['derive'] }
2424
env_logger = { workspace = true, optional = true }
2525
tokio = { workspace = true, features = ["macros"] }
26-
wasmtime = { workspace = true, features = ["async"] }
26+
wasmtime = { workspace = true, features = ["async", "anyhow"] }
2727
wasmtime-wasi = { workspace = true, features = ["p1"] }
2828
wasmtime-wizer = { workspace = true, features = ["wasmtime"] }
2929

src/bin/wizer.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use std::fs;
22
use std::io::{self, BufRead, Write};
33
use std::path::PathBuf;
44

5-
use anyhow::{anyhow, Context as _, Result};
5+
use anyhow::{Result, anyhow};
6+
use wasmtime::error::Context;
67
use clap::Parser;
78
use wizer::Wizer;
89

@@ -246,15 +247,12 @@ async fn main() -> Result<()> {
246247
for preload in options.preload.iter() {
247248
if let Some((name, value)) = preload.split_once('=') {
248249
let module = wasmtime::Module::from_file(&engine, value)
249-
.map_err(|e| anyhow!(e))
250250
.context("failed to parse preload module")?;
251251
let instance = linker
252252
.instantiate(&mut store, &module)
253-
.map_err(|e| anyhow!(e))
254253
.context("failed to instantiate preload module")?;
255254
linker
256255
.instance(&mut store, name, instance)
257-
.map_err(|e| anyhow!(e))
258256
.context("failed to add preload's exports to linker")?;
259257
} else {
260258
anyhow::bail!(
@@ -270,8 +268,7 @@ async fn main() -> Result<()> {
270268
linker.define_unknown_imports_as_traps(module)?;
271269
linker.instantiate(store, module)
272270
})
273-
.await
274-
.map_err(|e| anyhow!(e))?;
271+
.await?;
275272

276273
output
277274
.write_all(&output_wasm)

0 commit comments

Comments
 (0)