fatality based errors (#4448)

* seed commit for fatality based errors

* fatality

* first draft of fatality

* cleanup

* differnt approach

* simplify

* first working version for enums, with documentation

* add split

* fix simple split test case

* extend README.md

* update fatality impl

* make tests passed

* apply fatality to first subsystem

* fatality fixes

* use fatality in a subsystem

* fix subsystemg

* fixup proc macro

* fix/test: log::*! do not execute when log handler is missing

* fix spelling

* rename Runtime2 to something sane

* allow nested split with `forward` annotations

* add free license

* enable and fixup all tests

* use external fatality

Makes this more reviewable.

* bump fatality dep

Avoid duplicate expander compilations.

* migrate availability distribution

* more fatality usage

* chore: bump fatality to 0.0.6

* fixup remaining subsystems

* chore: fmt

* make cargo spellcheck happy

* remove single instance of `#[fatal(false)]`

* last quality sweep

* fixup
This commit is contained in:
Bernhard Schuster
2022-02-25 18:25:26 +01:00
committed by GitHub
parent 85fa087405
commit d946582707
48 changed files with 425 additions and 659 deletions
+1 -1
View File
@@ -13,6 +13,7 @@ parity-scale-codec = { version = "3.0.0", default-features = false, features = [
pin-project = "1.0.9"
rand = "0.8.5"
thiserror = "1.0.30"
fatality = "0.0.6"
tracing = "0.1.31"
derive_more = "0.99.17"
lru = "0.7.2"
@@ -38,4 +39,3 @@ log = "0.4.13"
polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" }
lazy_static = "1.4.0"
polkadot-primitives-test-helpers = { path = "../../primitives/test-helpers" }
@@ -18,34 +18,18 @@
//! Error handling related code and Error/Result definitions.
use futures::channel::oneshot;
use thiserror::Error;
use polkadot_node_subsystem::errors::RuntimeApiError;
use polkadot_primitives::v1::SessionIndex;
pub type Result<T> = std::result::Result<T, Error>;
/// Errors for `Runtime` cache.
#[derive(Debug, Error, derive_more::From)]
#[error(transparent)]
#[allow(missing_docs)]
#[fatality::fatality(splitable)]
pub enum Error {
/// All fatal errors.
Fatal(Fatal),
/// All nonfatal/potentially recoverable errors.
NonFatal(NonFatal),
}
/// Fatal runtime errors.
#[derive(Debug, Error)]
pub enum Fatal {
/// Runtime API subsystem is down, which means we're shutting down.
#[fatal]
#[error("Runtime request got canceled")]
RuntimeRequestCanceled(oneshot::Canceled),
}
/// Errors for fetching of runtime information.
#[derive(Debug, Error)]
pub enum NonFatal {
/// Some request to the runtime failed.
/// For example if we prune a block we're requesting info about.
#[error("Runtime API error {0}")]
@@ -56,13 +40,15 @@ pub enum NonFatal {
NoSuchSession(SessionIndex),
}
pub type Result<T> = std::result::Result<T, Error>;
/// Receive a response from a runtime request and convert errors.
pub(crate) async fn recv_runtime<V>(
r: oneshot::Receiver<std::result::Result<V, RuntimeApiError>>,
) -> Result<V> {
let result = r
.await
.map_err(Fatal::RuntimeRequestCanceled)?
.map_err(NonFatal::RuntimeRequest)?;
.map_err(FatalError::RuntimeRequestCanceled)?
.map_err(JfyiError::RuntimeRequest)?;
Ok(result)
}
@@ -44,7 +44,7 @@ use crate::{
mod error;
use error::{recv_runtime, Result};
pub use error::{Error, Fatal, NonFatal};
pub use error::{Error, FatalError, JfyiError};
/// Configuration for construction a `RuntimeInfo`.
pub struct Config {
@@ -169,7 +169,7 @@ impl RuntimeInfo {
let session_info =
recv_runtime(request_session_info(parent, session_index, sender).await)
.await?
.ok_or(NonFatal::NoSuchSession(session_index))?;
.ok_or(JfyiError::NoSuchSession(session_index))?;
let validator_info = self.get_validator_info(&session_info).await?;
let full_info = ExtendedSessionInfo { session_info, validator_info };