vls_protocol/
error.rs

1use alloc::string::String;
2use alloc::string::ToString;
3use bitcoin::consensus::encode::Error as BitcoinError;
4use core::fmt::{Debug, Display, Formatter};
5use serde_bolt::bitcoin;
6
7/// Error
8#[derive(Debug, Clone)]
9pub enum Error {
10    UnexpectedType(u16),
11    BadFraming,
12    /// Bitcoin consensus decoding error
13    Bitcoin(String),
14    /// Includes the message type for trailing bytes
15    TrailingBytes(usize, u16),
16    ShortRead,
17    MessageTooLarge,
18    Eof,
19    Io(String),
20    DeveloperField,
21}
22
23// convert bitcoin consensus decode error to our error
24impl From<BitcoinError> for Error {
25    fn from(e: BitcoinError) -> Self {
26        Error::Bitcoin(e.to_string())
27    }
28}
29
30impl From<serde_bolt::io::Error> for Error {
31    fn from(e: serde_bolt::io::Error) -> Self {
32        Error::Io(e.to_string())
33    }
34}
35
36/// Result
37pub type Result<T> = core::result::Result<T, Error>;
38
39impl Display for Error {
40    fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
41        Debug::fmt(self, f)
42    }
43}
44
45#[cfg(feature = "std")]
46impl std::error::Error for Error {}