essential_relayer/
error.rs1use essential_types::{ContentAddress, Word};
2use thiserror::Error;
3
4pub type Result<T> = std::result::Result<T, Error>;
6
7pub(crate) type InternalResult<T> = std::result::Result<T, InternalError>;
9
10#[derive(Debug, Error)]
12pub(crate) enum InternalError {
13 #[error("a critical error occurred: {0}")]
15 Critical(#[from] Error),
16 #[error("a recoverable error occurred: {0}")]
18 Recoverable(#[from] RecoverableError),
19}
20
21pub(crate) type CriticalError = Error;
23
24#[derive(Debug, Error)]
27pub enum Error {
28 #[error("an error occurred when parsing the server url")]
30 UrlParse,
31 #[error("an overflow occurred when converting a number")]
33 Overflow,
34 #[error("a data sync error occurred: {0}")]
36 DataSyncFailed(#[from] DataSyncError),
37 #[error("an error occurred while building the http client: {0}")]
39 HttpClientBuild(reqwest::Error),
40 #[error("failed to acquire or use a DB connection: {0}")]
42 DbPoolRusqlite(#[from] essential_node_db::pool::AcquireThenRusqliteError),
43}
44
45#[derive(Debug, Error)]
48pub(crate) enum RecoverableError {
49 #[error("an error occurred in the stream from the server: {0}")]
51 Stream(#[from] std::io::Error),
52 #[error("an error occurred in a request to the server: {0}")]
54 BadServerResponse(reqwest::StatusCode),
55 #[error("an error occurred in the http client: {0}")]
57 HttpClient(#[from] reqwest::Error),
58 #[error("a new block was not sequentially after the last block. Got: {0}, expected: {1}")]
60 NonSequentialBlock(Word, Word),
61 #[error("the stream returned an error: {0}")]
63 StreamError(String),
64 #[error("a DB error occurred: {0}")]
66 Rusqlite(rusqlite::Error),
67}
68
69#[derive(Debug, Error)]
70pub enum DataSyncError {
72 #[error(
74 "While syncing blocks a fork was detected at block number {0}. Got: {1}, expected: {}", display_address(.2)
75 )]
76 Fork(Word, ContentAddress, Option<ContentAddress>),
77}
78
79fn display_address<T>(addr: &Option<T>) -> String
80where
81 T: core::fmt::Display,
82{
83 match addr {
84 Some(addr) => format!("{}", addr),
85 None => "None".to_string(),
86 }
87}
88
89impl From<std::io::Error> for InternalError {
90 fn from(e: std::io::Error) -> Self {
91 InternalError::Recoverable(RecoverableError::Stream(e))
92 }
93}