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
@@ -39,7 +39,7 @@ use polkadot_subsystem::{
};
use crate::{
error::{Fatal, Result},
error::{FatalError, Result},
metrics::{Metrics, FAILED, SUCCEEDED},
requester::session_cache::{BadValidators, SessionInfo},
LOG_TARGET,
@@ -185,7 +185,7 @@ impl FetchTask {
let (handle, kill) = oneshot::channel();
ctx.spawn("chunk-fetcher", running.run(kill).boxed())
.map_err(|e| Fatal::SpawnTask(e))?;
.map_err(|e| FatalError::SpawnTask(e))?;
Ok(FetchTask { live_in, state: FetchedState::Started(handle) })
} else {
@@ -39,8 +39,7 @@ use polkadot_subsystem::{
ActivatedLeaf, ActiveLeavesUpdate, LeafStatus, SubsystemContext,
};
use super::{Metrics, Result, LOG_TARGET};
use crate::error::Fatal;
use super::{FatalError, Metrics, Result, LOG_TARGET};
#[cfg(test)]
mod tests;
@@ -324,6 +323,9 @@ where
})
.await;
let ancestors = rx.await.map_err(Fatal::ChainApiSenderDropped)?.map_err(Fatal::ChainApi)?;
let ancestors = rx
.await
.map_err(FatalError::ChainApiSenderDropped)?
.map_err(FatalError::ChainApi)?;
Ok(ancestors)
}
@@ -26,7 +26,7 @@ use polkadot_primitives::v1::{
use polkadot_subsystem::SubsystemContext;
use crate::{
error::{Error, NonFatal},
error::{Error, Result},
LOG_TARGET,
};
@@ -100,7 +100,7 @@ impl SessionCache {
runtime: &mut RuntimeInfo,
parent: Hash,
with_info: F,
) -> Result<Option<R>, Error>
) -> Result<Option<R>>
where
Context: SubsystemContext,
F: FnOnce(&SessionInfo) -> R,
@@ -143,10 +143,10 @@ impl SessionCache {
///
/// We assume validators in a group are tried in reverse order, so the reported bad validators
/// will be put at the beginning of the group.
pub fn report_bad(&mut self, report: BadValidators) -> crate::Result<()> {
pub fn report_bad(&mut self, report: BadValidators) -> Result<()> {
let available_sessions = self.session_info_cache.iter().map(|(k, _)| *k).collect();
let session = self.session_info_cache.get_mut(&report.session_index).ok_or(
NonFatal::NoSuchCachedSession {
Error::NoSuchCachedSession {
available_sessions,
missing_session: report.session_index,
},
@@ -179,7 +179,7 @@ impl SessionCache {
runtime: &mut RuntimeInfo,
relay_parent: Hash,
session_index: SessionIndex,
) -> Result<Option<SessionInfo>, Error>
) -> Result<Option<SessionInfo>>
where
Context: SubsystemContext,
{