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

Commit

Permalink
fixup changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bernhard Schuster committed Nov 3, 2020
1 parent 8467f4a commit 53d16ea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
12 changes: 4 additions & 8 deletions client/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ pub enum Error {
/// Invalid listen multiaddress
#[error("Invalid listen multiaddress")]
InvalidListenMultiaddress,
/// Application specific error chain sequence forwarder.
#[error(transparent)]
Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
/// URI error.
#[error("Invalid URI; expecting either a secret URI or a public URI.")]
InvalidUri(crypto::PublicError),
Expand Down Expand Up @@ -79,10 +76,9 @@ pub enum Error {
/// Bytes are not decodable when interpreted as hexadecimal string.
#[error("Invalid hex base data")]
HexDataConversion(#[from] hex::FromHexError),
/// Shortcut type to specify types on the fly, discouraged.
#[deprecated = "Use `Forwarded` with an error type instead."]
#[error("Other: {0}")]
Other(String),
/// Application specific error chain sequence forwarder.
#[error(transparent)]
Application(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
}

impl std::convert::From<&str> for Error {
Expand All @@ -93,7 +89,7 @@ impl std::convert::From<&str> for Error {

impl std::convert::From<String> for Error {
fn from(s: String) -> Error {
Error::Input(s.to_string())
Error::Input(s)
}
}

Expand Down
5 changes: 2 additions & 3 deletions client/service/src/client/wasm_override.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ where
/// Returns a hashmap of the runtime version and wasm runtime code.
fn scrape_overrides(dir: &Path, executor: &E) -> Result<HashMap<u32, WasmBlob>> {

let handle_err = {
let dir = dir.to_owned();
let handle_err = |e: std::io::Error | -> sp_blockchain::Error {
move |e: std::io::Error | -> sp_blockchain::Error {
sp_blockchain::Error::WasmOverrideIo(dir, e)
sp_blockchain::Error::WasmOverrideIo(dir.to_owned(), e)
}
};

Expand Down
23 changes: 19 additions & 4 deletions primitives/blockchain/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

//! Substrate client possible errors.

use std::{self, result};
use std::{self, result, path::PathBuf};
use sp_state_machine;
use sp_runtime::transaction_validity::TransactionValidityError;
use sp_consensus;
Expand Down Expand Up @@ -65,6 +65,7 @@ pub enum Error {
ApplyExtrinsicFailed(#[from] ApplyExtrinsicFailed),

/// Execution error.
// `inner` cannot be made member, since it lacks `std::error::Error` trait bounds.
#[error("Execution failed: {0:?}")]
Execution(Box<dyn sp_state_machine::Error>),

Expand Down Expand Up @@ -166,14 +167,16 @@ pub enum Error {
WasmOverrideIo(PathBuf, #[source] std::io::Error),

#[error("Overwriting WASM requires a directory where local \
WASM is stored. {0} is not a directory", .0.display())]
WASM is stored. {} is not a directory", .0.display())]
WasmOverrideNotADirectory(PathBuf),

#[error("Duplicate WASM Runtimes found: \n{}\n", .0.join("\n") )]
DuplicateWasmRuntime(Vec<String>),

/// A convenience variant for String
#[deprecated(note = "Introduce more typed error variants as needed")]
#[error(transparent)]
Foreign(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),

/// Should be avoided if possible, use `Foreign` instead.
#[error("{0}")]
Msg(String),
}
Expand All @@ -190,6 +193,18 @@ impl From<Box<dyn sp_state_machine::Error>> for Error {
}
}

impl From<String> for Error {
fn from(msg: String) -> Self {
Self::Msg(msg)
}
}
impl From<&str> for Error {
fn from(msg: &str) -> Self {
Self::Msg(msg.to_owned())
}
}


impl Error {
/// Chain a blockchain error.
pub fn from_blockchain(e: Box<Error>) -> Self {
Expand Down

0 comments on commit 53d16ea

Please sign in to comment.