Skip to content

Commit 4691149

Browse files
tdimitrovbkchr
authored andcommitted
Expose UnknownBlock error via ApiError (paritytech#12707)
* Expose `UnknownBlock` error via `ApiError` In [certain cases](https://github.com/paritytech/polkadot/issues/5885) a runtime api is called for an unknown block. For example a block which is already pruned or on an abandon fork. In such cases the correct error is returned but it is wrapped in `ApiError::Application` and the only way to figure out what is the problem is to inspect the actual message in the error. In polkadot for example this usually happens when the runtime api version is being queried. It's beneficial to be able to clearly separate such errors so i that when they occur the client side can handle them more gracefully. E.g. log less stressful error message than `State already discarded for BlockId` or cancel any pending work related on this block. * Update primitives/api/src/lib.rs Co-authored-by: Bastian Köcher <[email protected]> Co-authored-by: Bastian Köcher <[email protected]>
1 parent 929a0a4 commit 4691149

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

primitives/api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ pub enum ApiError {
519519
StateBackendIsNotTrie,
520520
#[error(transparent)]
521521
Application(#[from] Box<dyn std::error::Error + Send + Sync>),
522+
#[error("Api called for an unknown Block: {0}")]
523+
UnknownBlock(String),
522524
}
523525

524526
/// Extends the runtime api implementation with some common functionality.

primitives/blockchain/src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl From<Box<dyn sp_state_machine::Error>> for Error {
191191
impl From<Error> for ApiError {
192192
fn from(err: Error) -> ApiError {
193193
match err {
194+
Error::UnknownBlock(msg) => ApiError::UnknownBlock(msg),
194195
Error::RuntimeApiError(err) => err,
195196
e => ApiError::Application(Box::new(e)),
196197
}

0 commit comments

Comments
 (0)