spacetimedb_lib/
error.rs

1use std::fmt;
2
3/// A wrapper for using on test so the error display nicely
4pub struct TestError {
5    pub error: Box<dyn std::error::Error>,
6}
7
8impl fmt::Debug for TestError {
9    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
10        // Format the error in yellow
11        write!(f, "\x1b[93m{}\x1b[0m", self.error)
12    }
13}
14
15impl<E: std::error::Error + 'static> From<E> for TestError {
16    fn from(e: E) -> Self {
17        Self { error: Box::new(e) }
18    }
19}
20
21/// A wrapper for using [Result] in tests, so it display nicely
22pub type ResultTest<T> = Result<T, TestError>;