Skip to content

Commit 71f3146

Browse files
authored
Error handling (#32)
* better error handling * fix several error handling mechanisms
1 parent f1a1031 commit 71f3146

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

crates/app/src/extensions.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::{pin::Pin, task::Poll};
2-
31
use futures::{FutureExt, Stream, ready};
42
use pin_project_lite::pin_project;
3+
use std::{pin::Pin, task::Poll};
54
use void_types::Block;
65

76
#[cfg(test)]
@@ -95,9 +94,11 @@ where
9594
*this.post_extension = Some(post_extension);
9695
break Some((block, derived));
9796
} else if let Some(block) = ready!(this.stream.as_mut().poll_next(cx)) {
98-
let state_transition_func = this.state_transition_func.take().unwrap();
99-
let pre_extension = this.pre_extension.take().unwrap();
100-
let post_extension = this.post_extension.take().unwrap();
97+
// Process block.
98+
let state_transition_func =
99+
this.state_transition_func.take().expect("is always Some");
100+
let pre_extension = this.pre_extension.take().expect("is always Some");
101+
let post_extension = this.post_extension.take().expect("is always Some");
101102
let state = this.state.clone();
102103
this.access_fut.set(Some(
103104
async move {
@@ -120,6 +121,7 @@ where
120121
.boxed(),
121122
));
122123
} else {
124+
// Stream ended.
123125
break None;
124126
}
125127
})

crates/app/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#![deny(missing_docs)]
22
//! This create provides helpers for building streams that turn blocks into state and state into proofs.
33
4-
use std::collections::VecDeque;
5-
use std::pin::Pin;
6-
use std::task::Poll;
7-
use tracing::{Instrument, debug, error, info, instrument, instrument::Instrumented, warn};
8-
94
use futures::FutureExt;
105
use futures::Stream;
116
use futures::ready;
127
use pin_project_lite::pin_project;
8+
use std::collections::VecDeque;
9+
use std::pin::Pin;
10+
use std::task::Poll;
11+
use tracing::{Instrument, debug, error, info, instrument, instrument::Instrumented, warn};
1312
use void_types::Block;
1413
use void_types::Height;
1514
use void_types::Signed;
@@ -434,6 +433,7 @@ where
434433
*this.state_transition_func = Some(state_transition_func);
435434
break Some((block, derived));
436435
} else if let Some(block) = ready!(this.stream.as_mut().poll_next(cx)) {
436+
// Process block.
437437
let state_transition_func = this.state_transition_func.take().unwrap();
438438
let state = this.state.clone();
439439
this.access_fut.set(Some(
@@ -449,6 +449,7 @@ where
449449
.boxed(),
450450
));
451451
} else {
452+
// Stream ended.
452453
break None;
453454
}
454455
})
@@ -697,12 +698,14 @@ impl Notification {
697698

698699
/// Notify all receivers.
699700
pub fn notify(&self) {
701+
// Ignore send error - if no receivers are listening, notification can be dropped
700702
let _ = self.tx.send(());
701703
}
702704

703705
/// Wait for a notification.
704-
pub async fn wait(&mut self) {
705-
let _ = self.rx.changed().await;
706+
/// Returns an error if the sender has been dropped.
707+
pub async fn wait(&mut self) -> Result<(), tokio::sync::watch::error::RecvError> {
708+
self.rx.changed().await
706709
}
707710
}
708711

crates/types/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ impl<T> Lock<T> {
7878
where
7979
F: FnOnce(&mut T) -> R,
8080
{
81-
let mut lock = self.lock.lock().unwrap();
81+
// Not attempting poison recovery.
82+
let mut lock = self.lock.lock().expect("poisoned lock");
8283
f(&mut lock)
8384
}
8485
}

0 commit comments

Comments
 (0)