Skip to content

Commit

Permalink
fix: better error handling with deimos error in seq / lc start()
Browse files Browse the repository at this point in the history
  • Loading branch information
sebasti810 authored and distractedm1nd committed Jul 8, 2024
1 parent 8e254d4 commit 0b47213
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum GeneralError {
InvalidPublicKey,
#[error("Invalid signature")]
InvalidSignature,
#[error("Failed to start webserver")]
WebserverError,
}

#[derive(Error, Debug)]
Expand Down
22 changes: 15 additions & 7 deletions src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tokio::{
Mutex,
},
task::spawn,
time::{interval, sleep},
time::interval,
};

use crate::{
Expand All @@ -31,7 +31,7 @@ use crate::{

#[async_trait]
pub trait NodeType {
async fn start(self: Arc<Self>) -> std::result::Result<(), std::io::Error>;
async fn start(self: Arc<Self>) -> std::result::Result<(), DeimosError>;
// async fn stop(&self) -> Result<(), String>;
}

Expand All @@ -53,9 +53,13 @@ pub struct LightClient {

#[async_trait]
impl NodeType for Sequencer {
async fn start(self: Arc<Self>) -> std::result::Result<(), std::io::Error> {
async fn start(self: Arc<Self>) -> std::result::Result<(), DeimosError> {
// start listening for new headers to update sync target
self.da.start().await.unwrap();
if let Err(e) = self.da.start().await {
return Err(DeimosError::DataAvailability(
DataAvailabilityError::InitializationError(e.to_string()),
));
}

let derived_keys = self.db.get_derived_keys();
match derived_keys {
Expand All @@ -73,13 +77,17 @@ impl NodeType for Sequencer {

self.clone().main_loop().await;
self.clone().da_loop().await;
self.clone().ws.start(self.clone()).await
self.clone()
.ws
.start(self.clone())
.await
.map_err(|_| DeimosError::General(GeneralError::WebserverError))
}
}

#[async_trait]
impl NodeType for LightClient {
async fn start(self: Arc<Self>) -> std::result::Result<(), std::io::Error> {
async fn start(self: Arc<Self>) -> std::result::Result<(), DeimosError> {
// start listening for new headers to update sync target
self.da.start().await.unwrap();

Expand Down Expand Up @@ -144,7 +152,7 @@ impl NodeType for LightClient {

handle
.await
.map_err(|e| std::io::Error::new(ErrorKind::Other, format!("Join error: {}", e)))
.map_err(|_| DeimosError::General(GeneralError::WebserverError))
}
}

Expand Down

0 comments on commit 0b47213

Please sign in to comment.