Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Migrate CLI flags to `wasmtime::error` (#12260)

Nick Fitzgeraldb11f867572ef
diff --git a/Cargo.lock b/Cargo.lock
index bf75d7bf9f..d6b94ba08c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4703,7 +4703,6 @@ dependencies = [
name = "wasmtime-cli-flags"
version = "42.0.0"
dependencies = [
- "anyhow",
"clap",
"file-per-thread-logger",
"rayon",
diff --git a/crates/cli-flags/Cargo.toml b/crates/cli-flags/Cargo.toml
index ab5bebba76..83823ad772 100644
--- a/crates/cli-flags/Cargo.toml
+++ b/crates/cli-flags/Cargo.toml
@@ -13,7 +13,6 @@ rust-version.workspace = true
workspace = true
[dependencies]
-anyhow = { workspace = true, features = ['std'] }
clap = { workspace = true }
file-per-thread-logger = { workspace = true, optional = true }
tracing-subscriber = { workspace = true, optional = true }
diff --git a/crates/cli-flags/src/lib.rs b/crates/cli-flags/src/lib.rs
index ae595955e9..51fbd9b1ea 100644
--- a/crates/cli-flags/src/lib.rs
+++ b/crates/cli-flags/src/lib.rs
@@ -1,6 +1,5 @@
//! Contains the common Wasmtime command line interface (CLI) flags.
-use anyhow::{Context, Result};
use clap::Parser;
use serde::Deserialize;
use std::{
@@ -8,7 +7,7 @@ use std::{
path::{Path, PathBuf},
time::Duration,
};
-use wasmtime::Config;
+use wasmtime::{Config, Result, bail, error::Context as _};
pub mod opt;
@@ -606,7 +605,7 @@ macro_rules! match_feature {
#[cfg(not(feature = $feat))]
{
if let Some($p) = $config {
- anyhow::bail!(concat!("support for ", $feat, " disabled at compile time"));
+ bail!(concat!("support for ", $feat, " disabled at compile time"));
}
}
};
@@ -681,7 +680,7 @@ impl CommonOptions {
}
#[cfg(not(feature = "logging"))]
if self.debug.log_to_files == Some(true) || self.debug.logging == Some(true) {
- anyhow::bail!("support for logging disabled at compile time");
+ bail!("support for logging disabled at compile time");
}
Ok(())
}
@@ -720,7 +719,7 @@ impl CommonOptions {
#[cfg(feature = "coredump")]
config.coredump_on_trap(true);
#[cfg(not(feature = "coredump"))]
- anyhow::bail!("support for coredumps disabled at compile time");
+ bail!("support for coredumps disabled at compile time");
}
match_feature! {
["cranelift" : self.opts.opt_level]
@@ -761,7 +760,7 @@ impl CommonOptions {
}
#[cfg(not(feature = "cranelift"))]
if !self.codegen.cranelift.is_empty() {
- anyhow::bail!("support for cranelift disabled at compile time");
+ bail!("support for cranelift disabled at compile time");
}
#[cfg(feature = "cache")]
@@ -775,7 +774,7 @@ impl CommonOptions {
}
#[cfg(not(feature = "cache"))]
if self.codegen.cache == Some(true) {
- anyhow::bail!("support for caching disabled at compile time");
+ bail!("support for caching disabled at compile time");
}
match_feature! {
@@ -860,7 +859,7 @@ impl CommonOptions {
#[cfg(not(any(feature = "async", feature = "stack-switching")))]
{
if let Some(_size) = self.wasm.async_stack_size {
- anyhow::bail!(concat!(
+ bail!(concat!(
"support for async/stack-switching disabled at compile time"
));
}
@@ -963,15 +962,13 @@ impl CommonOptions {
if self.opts.pooling_memory_protection_keys.is_some()
&& !self.opts.pooling_allocator.unwrap_or(false)
{
- anyhow::bail!("memory protection keys require the pooling allocator");
+ bail!("memory protection keys require the pooling allocator");
}
if self.opts.pooling_max_memory_protection_keys.is_some()
&& !self.opts.pooling_memory_protection_keys.is_some()
{
- anyhow::bail!(
- "max memory protection keys requires memory protection keys to be enabled"
- );
+ bail!("max memory protection keys requires memory protection keys to be enabled");
}
match_feature! {
@@ -1057,7 +1054,7 @@ impl CommonOptions {
config.$method(enable);
#[cfg(not(feature = $feature))]
if enable && all.is_none() {
- anyhow::bail!("support for {} was disabled at compile-time", $feature);
+ bail!("support for {} was disabled at compile-time", $feature);
}
}
)*)
@@ -1083,7 +1080,7 @@ impl CommonOptions {
config.wasm_component_model_gc(enable);
#[cfg(not(all(feature = "component-model", feature = "gc")))]
if enable && all.is_none() {
- anyhow::bail!("support for `component-model-gc` was disabled at compile time")
+ bail!("support for `component-model-gc` was disabled at compile time")
}
}
diff --git a/crates/cli-flags/src/opt.rs b/crates/cli-flags/src/opt.rs
index b8c99e4330..c8c8ef4e20 100644
--- a/crates/cli-flags/src/opt.rs
+++ b/crates/cli-flags/src/opt.rs
@@ -6,12 +6,12 @@
//! option parsing is contained exclusively within this module.
use crate::{KeyValuePair, WasiNnGraph};
-use anyhow::{Result, bail};
use clap::builder::{StringValueParser, TypedValueParser, ValueParserFactory};
use clap::error::{Error, ErrorKind};
use serde::de::{self, Visitor};
use std::time::Duration;
use std::{fmt, marker};
+use wasmtime::{Result, bail};
/// Characters which can be safely ignored while parsing numeric options to wasmtime
const IGNORED_NUMBER_CHARS: [char; 1] = ['_'];