use alloc::string::String;
use cubecl_environment::backtrace::BackTrace;
use thiserror::Error;
#[derive(Error, Clone)]
#[cfg_attr(serializable, derive(serde::Serialize, serde::Deserialize))]
#[error("{reason}\nBacktrace:\n{backtrace}")]
pub struct DevicePoison {
pub reason: String,
#[cfg_attr(serializable, serde(skip))]
pub backtrace: BackTrace,
}
impl DevicePoison {
pub fn new(reason: impl Into<String>) -> Self {
Self {
reason: reason.into(),
backtrace: BackTrace::capture(),
}
}
}
impl core::fmt::Debug for DevicePoison {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "{self}")
}
}