1use alloc::string::String;
4use cubecl_environment::backtrace::BackTrace;
5use thiserror::Error;
6
7#[derive(Error, Clone)]
11#[cfg_attr(serializable, derive(serde::Serialize, serde::Deserialize))]
12#[error("{reason}\nBacktrace:\n{backtrace}")]
13pub struct DevicePoison {
14 pub reason: String,
16 #[cfg_attr(serializable, serde(skip))]
18 pub backtrace: BackTrace,
19}
20
21impl DevicePoison {
22 pub fn new(reason: impl Into<String>) -> Self {
24 Self {
25 reason: reason.into(),
26 backtrace: BackTrace::capture(),
27 }
28 }
29}
30
31impl core::fmt::Debug for DevicePoison {
32 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
33 write!(f, "{self}")
34 }
35}