#![warn(clippy::cast_sign_loss)]
#[cfg(feature = "preview2")]
pub mod preview2;
#[cfg(feature = "wasi-common-deprecations")]
#[deprecated(
since = "18.0.0",
note = "The wasmtime_wasi::sync module's functionalty has been moved to
wasi_common::sync. This re-export will be removed from wasmtime_wasi in
19.0"
)]
pub mod sync {
pub use wasi_common::sync::*;
}
#[cfg(feature = "wasi-common-deprecations")]
#[allow(deprecated)] #[deprecated(
since = "18.0.0",
note = "The wasmtime_wasi module's root export of wasmtime_wasi::sync has
been moved to wasi_common::sync. This re-export will be removed from
wasmtime_wasi in 19.0"
)]
pub use sync::*;
#[cfg(feature = "tokio")]
#[deprecated(
since = "18.0.0",
note = "The wasmtime_wasi::tokio module's functionalty has been moved to
wasi_common::tokio. This re-export will be removed from wasmtime_wasi in
19.0"
)]
pub mod tokio {
pub use wasi_common::tokio::*;
}
#[cfg(feature = "exit")]
#[deprecated(
since = "18.0.0",
note = "This legacy functionality is migrated to the wasi-common crate, and will be removed in 19.0."
)]
pub fn maybe_exit_on_error(e: anyhow::Error) -> anyhow::Error {
use std::process;
use wasmtime::Trap;
if let Some(exit) = e
.downcast_ref::<preview2::I32Exit>()
.map(|exit| exit.process_exit_code())
{
process::exit(exit)
}
let code = e.downcast_ref::<wasi_common::I32Exit>().map(|e| e.0);
if let Some(exit) = code {
if cfg!(windows) && exit >= 3 {
process::exit(1);
}
process::exit(exit);
}
if e.is::<Trap>() {
eprintln!("Error: {:?}", e);
cfg_if::cfg_if! {
if #[cfg(unix)] {
process::exit(rustix::process::EXIT_SIGNALED_SIGABRT);
} else if #[cfg(windows)] {
process::exit(3);
}
}
}
e
}