ffd6760f8a9edda95b1c8ca33017e0f80c6d0fa0
[rust-lightning] / lightning-rapid-gossip-sync / src / error.rs
1 use core::fmt::Debug;
2 use core::fmt::Formatter;
3 use lightning::ln::msgs::{DecodeError, LightningError};
4
5 /// All-encompassing standard error type that processing can return
6 pub enum GraphSyncError {
7         /// Error trying to read the update data, typically due to an erroneous data length indication
8         /// that is greater than the actual amount of data provided
9         DecodeError(DecodeError),
10         /// Error applying the patch to the network graph, usually the result of updates that are too
11         /// old or missing prerequisite data to the application of updates out of order
12         LightningError(LightningError),
13 }
14
15 impl From<lightning::io::Error> for GraphSyncError {
16         fn from(error: lightning::io::Error) -> Self {
17                 Self::DecodeError(DecodeError::Io(error.kind()))
18         }
19 }
20
21 impl From<DecodeError> for GraphSyncError {
22         fn from(error: DecodeError) -> Self {
23                 Self::DecodeError(error)
24         }
25 }
26
27 impl From<LightningError> for GraphSyncError {
28         fn from(error: LightningError) -> Self {
29                 Self::LightningError(error)
30         }
31 }
32
33 impl Debug for GraphSyncError {
34         fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
35                 match self {
36                         GraphSyncError::DecodeError(e) => f.write_fmt(format_args!("DecodeError: {:?}", e)),
37                         GraphSyncError::LightningError(e) => f.write_fmt(format_args!("LightningError: {:?}", e))
38                 }
39         }
40 }