mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 08:11:03 +00:00
remove error wrapper type (#1871)
* get rid of glue wrapper error type * cargo update -p sp-io * cargo update -p sp-io * "Update Substrate" Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: parity-processbot <>
This commit is contained in:
committed by
GitHub
parent
bbf7fc8d0b
commit
8a305ac963
Generated
+145
-139
File diff suppressed because it is too large
Load Diff
@@ -14,6 +14,7 @@ readme = "README.md"
|
||||
[dependencies]
|
||||
cli = { package = "polkadot-cli", path = "cli" }
|
||||
color-eyre = "0.5.6"
|
||||
thiserror = "1"
|
||||
futures = "0.3.4"
|
||||
service = { package = "polkadot-service", path = "node/service" }
|
||||
parity-util-mem = { version = "*", default-features = false, features = ["jemalloc-global"] }
|
||||
|
||||
@@ -15,6 +15,7 @@ crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.11"
|
||||
thiserror = "1.0.21"
|
||||
structopt = { version = "0.3.8", optional = true }
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
@@ -17,6 +17,7 @@ sp-wasm-interface = { git = "https://github.com/paritytech/substrate", branch =
|
||||
polkadot-core-primitives = { path = "../core-primitives", default-features = false }
|
||||
|
||||
# all optional crates.
|
||||
thiserror = { version = "1.0.21", optional = true }
|
||||
derive_more = { version = "0.99.11", optional = true }
|
||||
serde = { version = "1.0.102", default-features = false, features = [ "derive" ], optional = true }
|
||||
sp-externalities = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
|
||||
@@ -34,6 +35,7 @@ default = ["std"]
|
||||
wasm-api = []
|
||||
std = [
|
||||
"codec/std",
|
||||
"thiserror",
|
||||
"derive_more",
|
||||
"serde/std",
|
||||
"sp-std/std",
|
||||
|
||||
@@ -81,63 +81,61 @@ pub enum ExecutionMode {
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
/// Candidate validation error.
|
||||
pub enum ValidationError {
|
||||
/// Validation failed due to internal reasons. The candidate might still be valid.
|
||||
Internal(InternalError),
|
||||
#[error(transparent)]
|
||||
Internal(#[from] InternalError),
|
||||
/// Candidate is invalid.
|
||||
InvalidCandidate(InvalidCandidate),
|
||||
#[error(transparent)]
|
||||
InvalidCandidate(#[from] InvalidCandidate),
|
||||
}
|
||||
|
||||
/// Error type that indicates invalid candidate.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum InvalidCandidate {
|
||||
/// Wasm executor error.
|
||||
#[display(fmt = "WASM executor error: {:?}", _0)]
|
||||
WasmExecutor(sc_executor::error::Error),
|
||||
#[error("WASM executor error")]
|
||||
WasmExecutor(#[from] sc_executor::error::Error),
|
||||
/// Call data is too large.
|
||||
#[display(fmt = "Validation parameters are {} bytes, max allowed is {}", _0, MAX_RUNTIME_MEM)]
|
||||
#[from(ignore)]
|
||||
#[error("Validation parameters are {0} bytes, max allowed is {}", MAX_RUNTIME_MEM)]
|
||||
ParamsTooLarge(usize),
|
||||
/// Code size it too large.
|
||||
#[display(fmt = "WASM code is {} bytes, max allowed is {}", _0, MAX_CODE_MEM)]
|
||||
#[error("WASM code is {0} bytes, max allowed is {}", MAX_CODE_MEM)]
|
||||
CodeTooLarge(usize),
|
||||
/// Error decoding returned data.
|
||||
#[display(fmt = "Validation function returned invalid data.")]
|
||||
#[error("Validation function returned invalid data.")]
|
||||
BadReturn,
|
||||
#[display(fmt = "Validation function timeout.")]
|
||||
#[error("Validation function timeout.")]
|
||||
Timeout,
|
||||
#[display(fmt = "External WASM execution error: {}", _0)]
|
||||
#[error("External WASM execution error: {0}")]
|
||||
ExternalWasmExecutor(String),
|
||||
}
|
||||
|
||||
impl core::convert::From<String> for InvalidCandidate {
|
||||
fn from(s: String) -> Self {
|
||||
Self::ExternalWasmExecutor(s)
|
||||
}
|
||||
}
|
||||
|
||||
/// Host error during candidate validation. This does not indicate an invalid candidate.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum InternalError {
|
||||
#[display(fmt = "IO error: {}", _0)]
|
||||
Io(std::io::Error),
|
||||
#[display(fmt = "System error: {}", _0)]
|
||||
System(Box<dyn std::error::Error + Send>),
|
||||
#[display(fmt = "Shared memory error: {}", _0)]
|
||||
#[error("IO error: {0}")]
|
||||
Io(#[from] std::io::Error),
|
||||
|
||||
#[error("System error: {0}")]
|
||||
System(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
|
||||
|
||||
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
|
||||
SharedMem(shared_memory::SharedMemError),
|
||||
#[display(fmt = "WASM worker error: {}", _0)]
|
||||
#[error("Shared memory error: {0}")]
|
||||
SharedMem(#[from] shared_memory::SharedMemError),
|
||||
|
||||
#[error("WASM worker error: {0}")]
|
||||
WasmWorker(String),
|
||||
}
|
||||
|
||||
impl std::error::Error for ValidationError {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
ValidationError::Internal(InternalError::Io(ref err)) => Some(err),
|
||||
ValidationError::Internal(InternalError::System(ref err)) => Some(&**err),
|
||||
#[cfg(not(any(target_os = "android", target_os = "unknown")))]
|
||||
ValidationError::Internal(InternalError::SharedMem(ref err)) => Some(err),
|
||||
ValidationError::InvalidCandidate(InvalidCandidate::WasmExecutor(ref err)) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Validate a candidate under the given validation code.
|
||||
///
|
||||
|
||||
+1
-33
@@ -20,40 +20,8 @@
|
||||
|
||||
use color_eyre::eyre;
|
||||
|
||||
use cli::Error as PolkaError;
|
||||
|
||||
use std::{error, fmt};
|
||||
|
||||
/// A helper to satisfy the requirements of `eyre`
|
||||
/// compatible errors, which require `Send + Sync`
|
||||
/// which are not satisfied by the `sp_*` crates.
|
||||
#[derive(Debug)]
|
||||
struct ErrorWrapper(std::sync::Arc<PolkaError>);
|
||||
|
||||
// nothing is going to be sent to another thread
|
||||
// it merely exists to glue two distinct error
|
||||
// types together where the requirements differ
|
||||
// with `Sync + Send` and without them for `wasm`.
|
||||
unsafe impl Sync for ErrorWrapper {}
|
||||
unsafe impl Send for ErrorWrapper {}
|
||||
|
||||
impl error::Error for ErrorWrapper {
|
||||
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
||||
(&*self.0).source().and_then(|e| e.source())
|
||||
}
|
||||
fn description(&self) -> &str {
|
||||
"Error Wrapper"
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ErrorWrapper {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}", &*self.0)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> eyre::Result<()> {
|
||||
color_eyre::install()?;
|
||||
cli::run().map_err(|e| ErrorWrapper(std::sync::Arc::new(e)))?;
|
||||
cli::run()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user