clementine_core/
errors.rs

1//! # Errors
2//!
3//! Error types are now in the `clementine-errors` crate and should be imported
4//! directly from there (e.g., `use clementine_errors::BridgeError;`).
5
6#[cfg(test)]
7mod tests {
8    use clementine_errors::{BitcoinRPCError, BridgeError, ErrorExt, TxError};
9    use eyre::Context;
10
11    #[test]
12    fn test_downcast() {
13        assert_eq!(
14            BridgeError::IntConversionError
15                .into_eyre()
16                .wrap_err("Some other error")
17                .into_eyre()
18                .wrap_err("some other")
19                .downcast_ref::<BridgeError>()
20                .expect("should downcast")
21                .to_string(),
22            BridgeError::IntConversionError.to_string()
23        );
24    }
25
26    #[test]
27    fn test_status_shows_all_errors_in_chain() {
28        let err: BridgeError = Err::<(), BridgeError>(BridgeError::BitcoinRPC(
29            BitcoinRPCError::TransactionNotConfirmed,
30        ))
31        .wrap_err(tonic::Status::deadline_exceeded("Error A"))
32        .wrap_err("Error B")
33        .expect_err("should be error")
34        .into();
35
36        let status: tonic::Status = err.into();
37        assert!(status.message().contains("Error A"));
38        assert!(status.message().contains("Error B"));
39        assert!(status.message().contains("Bitcoin"));
40    }
41
42    #[test]
43    fn test_tx_error_conversion() {
44        let tx_err = TxError::TxInputNotFound;
45        let bridge_err: BridgeError = tx_err.into();
46        assert!(matches!(bridge_err, BridgeError::Transaction(_)));
47    }
48}