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#[derive(Debug, Clone)]
9pub enum Error {
10 UnexpectedType(u16),
11 BadFraming,
12 Bitcoin(String),
14 TrailingBytes(usize, u16),
16 ShortRead,
17 MessageTooLarge,
18 Eof,
19 Io(String),
20 DeveloperField,
21}
22
23impl 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
36pub 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 {}