use crate::prelude::*;
use core::fmt;
macro_rules! bail_bug {
($($arg:tt)*) => {{
static POS: (&'static str, u32) = (file!(), line!());
$crate::bail!(crate::WasmtimeBug::new(format_args!($($arg)*), &POS))
}}
}
pub(crate) use bail_bug;
#[derive(Debug)]
pub struct WasmtimeBug {
message: String,
file: &'static str,
line: u32,
}
impl WasmtimeBug {
#[cold]
pub(crate) fn new(message: fmt::Arguments<'_>, pos: &'static (&'static str, u32)) -> Self {
if cfg!(debug_assertions) {
panic!("BUG: {message}");
}
Self {
message: message.to_string(),
file: pos.0,
line: pos.1,
}
}
}
impl fmt::Display for WasmtimeBug {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"\
BUG: {}
location: {}:{}
version: {}
This is a bug in Wasmtime that was not thought to be reachable. A panic is
not happening to avoid taking down the thread, but this trap is being injected
into WebAssembly guests to prevent their execution. The Wasmtime project would
appreciate a bug report with a copy of this message to help investigate what
happened. If you're able to provide a reproduction, that would be appreciated,
but it is not necessary to do so and instead indicating that this is reachable
is a sufficiently actionable bug for maintainers to investigate.
",
self.message,
self.file,
self.line,
env!("CARGO_PKG_VERSION"),
)
}
}
impl core::error::Error for WasmtimeBug {}