tonlib_core/message/
error.rs

1use core::fmt;
2
3use thiserror::Error;
4
5use crate::cell::TonCellError;
6
7#[derive(Error, Debug)]
8pub enum TonMessageError {
9    #[error("ForwardTonAmountIsNegative error: Forward_ton_amount must be positive when specifying forward_payload")]
10    ForwardTonAmountIsNegative,
11
12    #[error("NaCl cryptographic error ({0})")]
13    NaclCryptographicError(String),
14
15    #[error("TonCellError ({0})")]
16    TonCellError(#[from] TonCellError),
17
18    #[error("Invalid message ({0})")]
19    InvalidMessage(InvalidMessage),
20
21    #[error("Internal error ({0})")]
22    InternalError(String),
23}
24
25#[derive(Clone, PartialEq)]
26pub struct InvalidMessage {
27    pub opcode: Option<u32>,
28    pub query_id: Option<u64>,
29    pub message: String,
30}
31
32impl fmt::Display for InvalidMessage {
33    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
34        write!(
35            f,
36            "InvalidMessage {{ opcode: {:?}, query_id: {:?}, message: {} }}",
37            self.opcode, self.query_id, self.message
38        )
39    }
40}
41
42impl std::fmt::Debug for InvalidMessage {
43    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44        f.debug_struct("InvalidMessage")
45            .field("opcode", &self.opcode.map(|op| format!("{:#x}", op)))
46            .field("query_id", &self.query_id)
47            .field("message", &self.message)
48            .finish()
49    }
50}