mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 21:41:12 +00:00
Expunge error-chain (feat. tomaka) (#2662)
* Remove error_chain * Expunge error-chain from rpc and service. * Expunge from transaction pool. * Expunge from node/cli * Expunge from keystore. * Remove some boilerplate. * Fix remaining stuff. * Improve on deprecation message. * Fix issues. * Fix trnsaction pool tests. * Fix the rest. * Fix borked merge. * Update lock
This commit is contained in:
committed by
Gavin Wood
parent
69ffec5822
commit
c162fc5ff1
@@ -14,34 +14,47 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use error_chain::*;
|
||||
use client;
|
||||
use crate::rpc;
|
||||
use crate::errors;
|
||||
|
||||
error_chain! {
|
||||
foreign_links {
|
||||
Client(client::error::Error) #[doc = "Client error"];
|
||||
}
|
||||
/// State RPC Result type.
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
errors {
|
||||
/// Provided block range couldn't be resolved to a list of blocks.
|
||||
InvalidBlockRange(from: String, to: String, details: String) {
|
||||
description("Invalid block range"),
|
||||
display("Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details),
|
||||
}
|
||||
/// Not implemented yet
|
||||
Unimplemented {
|
||||
description("not implemented yet"),
|
||||
display("Method Not Implemented"),
|
||||
/// State RPC errors.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
pub enum Error {
|
||||
/// Client error.
|
||||
Client(client::error::Error),
|
||||
/// Provided block range couldn't be resolved to a list of blocks.
|
||||
#[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)]
|
||||
InvalidBlockRange {
|
||||
from: String,
|
||||
to: String,
|
||||
details: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Error::Client(ref err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Base code for all state errors.
|
||||
const BASE_ERROR: i64 = 4000;
|
||||
|
||||
impl From<Error> for rpc::Error {
|
||||
fn from(e: Error) -> Self {
|
||||
match e {
|
||||
Error(ErrorKind::Unimplemented, _) => errors::unimplemented(),
|
||||
Error::InvalidBlockRange { .. } => rpc::Error {
|
||||
code: rpc::ErrorCode::ServerError(BASE_ERROR + 1),
|
||||
message: format!("{}", e),
|
||||
data: None,
|
||||
},
|
||||
e => errors::internal(e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use error_chain::bail;
|
||||
use log::{warn, trace};
|
||||
use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata};
|
||||
use jsonrpc_derive::rpc;
|
||||
@@ -148,11 +147,15 @@ pub trait StateApi<Hash> {
|
||||
|
||||
/// New storage subscription
|
||||
#[pubsub(subscription = "state_storage", subscribe, name = "state_subscribeStorage")]
|
||||
fn subscribe_storage(&self, metadata: Self::Metadata, subscriber: Subscriber<StorageChangeSet<Hash>>, keys: Option<Vec<StorageKey>>);
|
||||
fn subscribe_storage(
|
||||
&self, metadata: Self::Metadata, subscriber: Subscriber<StorageChangeSet<Hash>>, keys: Option<Vec<StorageKey>>
|
||||
);
|
||||
|
||||
/// Unsubscribe from storage subscription
|
||||
#[pubsub(subscription = "state_storage", unsubscribe, name = "state_unsubscribeStorage")]
|
||||
fn unsubscribe_storage(&self, metadata: Option<Self::Metadata>, id: SubscriptionId) -> RpcResult<bool>;
|
||||
fn unsubscribe_storage(
|
||||
&self, metadata: Option<Self::Metadata>, id: SubscriptionId
|
||||
) -> RpcResult<bool>;
|
||||
}
|
||||
|
||||
/// State API with subscriptions support.
|
||||
@@ -213,7 +216,7 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
||||
blocks.push(hdr.hash());
|
||||
last = hdr;
|
||||
} else {
|
||||
bail!(invalid_block_range(
|
||||
return Err(invalid_block_range(
|
||||
Some(from),
|
||||
Some(to),
|
||||
format!("Parent of {} ({}) not found", last.number(), last.hash()),
|
||||
@@ -221,7 +224,7 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
||||
}
|
||||
}
|
||||
if last.hash() != from.hash() {
|
||||
bail!(invalid_block_range(
|
||||
return Err(invalid_block_range(
|
||||
Some(from),
|
||||
Some(to),
|
||||
format!("Expected to reach `from`, got {} ({})", last.number(), last.hash()),
|
||||
@@ -241,7 +244,7 @@ impl<B, E, Block: BlockT, RA> State<B, E, Block, RA> where
|
||||
filtered_range,
|
||||
})
|
||||
},
|
||||
(from, to) => bail!(
|
||||
(from, to) => Err(
|
||||
invalid_block_range(from.as_ref(), to.as_ref(), "Invalid range or unknown block".into())
|
||||
),
|
||||
}
|
||||
@@ -483,7 +486,9 @@ impl<B, E, Block, RA> StateApi<Block::Hash> for State<B, E, Block, RA> where
|
||||
}
|
||||
|
||||
fn subscribe_runtime_version(&self, _meta: Self::Metadata, subscriber: Subscriber<RuntimeVersion>) {
|
||||
let stream = match self.client.storage_changes_notification_stream(Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())])) {
|
||||
let stream = match self.client.storage_changes_notification_stream(
|
||||
Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())])
|
||||
) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
let _ = subscriber.reject(error::Error::from(err).into());
|
||||
@@ -551,11 +556,15 @@ pub(crate) fn split_range(size: usize, middle: Option<usize>) -> (Range<usize>,
|
||||
(range1, range2)
|
||||
}
|
||||
|
||||
fn invalid_block_range<H: Header>(from: Option<&H>, to: Option<&H>, reason: String) -> error::ErrorKind {
|
||||
fn invalid_block_range<H: Header>(from: Option<&H>, to: Option<&H>, reason: String) -> error::Error {
|
||||
let to_string = |x: Option<&H>| match x {
|
||||
None => "unknown hash".into(),
|
||||
Some(h) => format!("{} ({})", h.number(), h.hash()),
|
||||
};
|
||||
|
||||
error::ErrorKind::InvalidBlockRange(to_string(from), to_string(to), reason)
|
||||
error::Error::InvalidBlockRange {
|
||||
from: to_string(from),
|
||||
to: to_string(to),
|
||||
details: reason,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use super::*;
|
||||
use self::error::{Error, ErrorKind};
|
||||
use self::error::Error;
|
||||
|
||||
use assert_matches::assert_matches;
|
||||
use consensus::BlockOrigin;
|
||||
@@ -80,7 +80,7 @@ fn should_call_contract() {
|
||||
|
||||
assert_matches!(
|
||||
client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()),
|
||||
Err(Error(ErrorKind::Client(client::error::Error::Execution(_)), _))
|
||||
Err(Error::Client(client::error::Error::Execution(_)))
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user