Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Expose UnknownBlock error via ApiError #12707

Merged
merged 3 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
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.
  • Loading branch information
tdimitrov committed Jan 10, 2023
commit 4b3c7478d31247c8556270b0c6ffa292c297d649
2 changes: 2 additions & 0 deletions primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ pub enum ApiError {
StateBackendIsNotTrie,
#[error(transparent)]
Application(#[from] Box<dyn std::error::Error + Send + Sync>),
#[error("Api called for an unknownBlock: {0}")]
tdimitrov marked this conversation as resolved.
Show resolved Hide resolved
UnknownBlock(String),
}

/// Extends the runtime api implementation with some common functionality.
Expand Down
1 change: 1 addition & 0 deletions primitives/blockchain/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ impl From<Box<dyn sp_state_machine::Error>> for Error {
impl From<Error> for ApiError {
fn from(err: Error) -> ApiError {
match err {
Error::UnknownBlock(msg) => ApiError::UnknownBlock(msg),
Error::RuntimeApiError(err) => err,
e => ApiError::Application(Box::new(e)),
}
Expand Down