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

chore/error: remove from str conversion and add deprecation notificat… #7472

Merged
39 commits merged into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8467f4a
chore/error: remove from str conversion and add deprecation notificat…
Oct 30, 2020
91744cd
fixup changes
Nov 3, 2020
c1085eb
fix test looking for gone ::Msg variant
Nov 3, 2020
524ee71
another test fix
Nov 4, 2020
2a09d3c
one is duplicate, the other is not, so duplicates reported are n-1
Nov 4, 2020
dbbd20f
darn spaces
drahnr Nov 10, 2020
8d021f0
remove pointless doc comments of error variants without any value
Nov 10, 2020
311a58f
Merge remote-tracking branch 'origin/master' into bernhard-error-chore
Nov 11, 2020
8b3f12b
low hanging fruits (for a tall person)
Nov 13, 2020
2dbc971
moar error type variants
Nov 14, 2020
3e94fa6
avoid the storage modules for now
Nov 17, 2020
666dd5f
chore remove pointless error generic
Nov 17, 2020
69e849b
fix test for mocks, add a bunch of non_exhaustive
Nov 17, 2020
d54cb37
max line width
Nov 17, 2020
10a2278
Merge remote-tracking branch 'origin/master' into bernhard-error-chore
Nov 18, 2020
66b6989
test fixes due to error changes
Nov 20, 2020
49fe444
fin
Nov 25, 2020
2b5f9d7
Merge remote-tracking branch 'origin/master' into bernhard-error-chore
Nov 25, 2020
ff81007
error outputs... again
Nov 25, 2020
13ba47b
undo stderr adjustments
Nov 26, 2020
3dda02d
Update client/consensus/slots/src/lib.rs
drahnr Nov 26, 2020
eb7805b
remove closure clutter
drahnr Nov 26, 2020
536f11e
more error types
Nov 26, 2020
bc40955
introduce ApiError
Nov 26, 2020
31f0259
extract Mock error
Nov 26, 2020
717ec7d
ApiError refactor
Nov 26, 2020
b4c1348
even more error types
Nov 26, 2020
cc2353d
the last for now
Nov 26, 2020
1d364ac
chore unused deps
Nov 26, 2020
56a0b2d
another extraction
Nov 26, 2020
c080594
reduce should panic, due to extended error messages
Nov 26, 2020
077301e
error test happiness
Nov 26, 2020
0983c88
shift error lines by one
Nov 27, 2020
0e9d696
doc tests
Nov 27, 2020
4b752b0
Merge remote-tracking branch 'origin/master' into bernhard-error-chore
Nov 27, 2020
35d2814
white space
drahnr Nov 27, 2020
13810eb
Into -> From
drahnr Nov 27, 2020
6df60d0
remove pointless codec
drahnr Nov 27, 2020
d0c0d24
avoid pointless self import
drahnr Nov 27, 2020
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
11 changes: 7 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions client/api/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,9 @@ pub mod tests {

pub type OkCallFetcher = Mutex<Vec<u8>>;

fn not_implemented_in_tests<T, E>() -> Ready<Result<T, E>>
where
E: std::convert::From<&'static str>,
fn not_implemented_in_tests<T>() -> Ready<Result<T, ClientError>>
{
futures::future::ready(Err("Not implemented on test node".into()))
futures::future::ready(Err(ClientError::Mock("Not implemented on test node")))
}

impl Fetcher<Block> for OkCallFetcher {
Expand Down
5 changes: 1 addition & 4 deletions client/basic-authorship/src/basic_authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ impl<A, B, Block, C> sp_consensus::Proposer<Block> for
}));

async move {
match rx.await {
Ok(x) => x,
Err(err) => Err(sp_blockchain::Error::Msg(err.to_string()))
}
rx.await?
}.boxed()
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ where
&state,
changes_trie_state.as_ref(),
parent_hash,
)?;
).map_err(|e| sp_blockchain::Error::StorageChanges(e))?;

Ok(BuiltBlock {
block: <Block as BlockT>::new(header, self.extrinsics),
Expand Down
45 changes: 21 additions & 24 deletions client/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,61 @@ pub type Result<T> = std::result::Result<T, Error>;

/// Error type for the CLI.
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
/// Io error
#[error(transparent)]
Io(#[from] std::io::Error),
/// Cli error

#[error(transparent)]
Cli(#[from] structopt::clap::Error),
/// Service error

#[error(transparent)]
Service(#[from] sc_service::Error),
/// Client error

#[error(transparent)]
Client(#[from] sp_blockchain::Error),
/// scale codec error

#[error(transparent)]
Codec(#[from] parity_scale_codec::Error),
/// Input error

#[error("Invalid input: {0}")]
Input(String),
/// 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),
/// Signature length mismatch.

#[error("Signature has an invalid length. Read {read} bytes, expected {expected} bytes")]
SignatureInvalidLength {
/// Amount of signature bytes read.
read: usize,
/// Expected number of signature bytes.
expected: usize,
},
/// Missing base path argument.

#[error("The base path is missing, please provide one")]
MissingBasePath,
/// Unknown key type specifier or missing key type specifier.

#[error("Unknown key type, must be a known 4-character sequence")]
KeyTypeInvalid,
/// Signature verification failed.

#[error("Signature verification failed")]
SignatureInvalid,
/// Storing a given key failed.

#[error("Key store operation failed")]
KeyStoreOperation,
/// An issue with the underlying key storage was encountered.

#[error("Key storage issue encountered")]
KeyStorage(#[from] sc_keystore::Error),
/// Bytes are not decodable when interpreted as hexadecimal string.
#[error("Invalid hex base data")]

#[error("Invalid hexadecimal string 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 +90,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
9 changes: 5 additions & 4 deletions client/consensus/slots/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,11 @@ impl<T: Clone> SlotDuration<T> {
}
}?;

if slot_duration.slot_duration() == 0 {
return Err(sp_blockchain::Error::Msg(
"Invalid value for slot_duration: the value must be greater than 0.".into(),
))
{
let slot_duration = slot_duration.slot_duration();
if slot_duration == 0u64 {
return Err(sp_blockchain::Error::SlotDurationInvalid(slot_duration))
}
}
drahnr marked this conversation as resolved.
Show resolved Hide resolved

Ok(slot_duration)
Expand Down
12 changes: 4 additions & 8 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,7 @@ impl<Block: BlockT> Backend<Block> {
let is_archive_pruning = config.pruning.is_archive();
let blockchain = BlockchainDb::new(db.clone())?;
let meta = blockchain.meta.clone();
let map_e = |e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from(
format!("State database error: {:?}", e)
);
let map_e = |e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e);
let state_db: StateDb<_, _> = StateDb::new(
config.pruning.clone(),
!config.source.supports_ref_counting(),
Expand Down Expand Up @@ -1059,7 +1057,7 @@ impl<Block: BlockT> Backend<Block> {

trace!(target: "db", "Canonicalize block #{} ({:?})", new_canonical, hash);
let commit = self.storage.state_db.canonicalize_block(&hash)
.map_err(|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from(format!("State database error: {:?}", e)))?;
.map_err(|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e))?;
apply_state_commit(transaction, commit);
};

Expand Down Expand Up @@ -1195,9 +1193,7 @@ impl<Block: BlockT> Backend<Block> {
number_u64,
&pending_block.header.parent_hash(),
changeset,
).map_err(|e: sc_state_db::Error<io::Error>|
sp_blockchain::Error::from(format!("State database error: {:?}", e))
)?;
).map_err(|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e))?;
apply_state_commit(&mut transaction, commit);

// Check if need to finalize. Genesis is always finalized instantly.
Expand Down Expand Up @@ -1352,7 +1348,7 @@ impl<Block: BlockT> Backend<Block> {
transaction.set_from_vec(columns::META, meta_keys::FINALIZED_BLOCK, lookup_key);

let commit = self.storage.state_db.canonicalize_block(&f_hash)
.map_err(|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from(format!("State database error: {:?}", e)))?;
.map_err(|e: sc_state_db::Error<io::Error>| sp_blockchain::Error::from_state_db(e))?;
apply_state_commit(transaction, commit);

if !f_num.is_zero() {
Expand Down
3 changes: 2 additions & 1 deletion client/light/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ pub fn check_execution_proof_with_make_header<Header, E, H, MakeNextHeader>(

// TODO: Remove when solved: https://github.com/paritytech/substrate/issues/5047
let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&trie_backend);
let runtime_code = backend_runtime_code.runtime_code()?;
let runtime_code = backend_runtime_code.runtime_code()
.map_err(|_e| ClientError::RuntimeCodeMissing)?;

execution_proof_check_on_trie_backend::<H, Header::Number, _, _>(
&trie_backend,
Expand Down
14 changes: 7 additions & 7 deletions client/light/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ impl<E, Block, H, S> FetchChecker<Block> for LightDataChecker<E, H, Block, S>
convert_hash(request.header.state_root()),
remote_proof,
request.keys.iter(),
).map_err(Into::into)
).map_err(|e| ClientError::from(e))
}

fn check_read_child_proof(
Expand All @@ -249,14 +249,14 @@ impl<E, Block, H, S> FetchChecker<Block> for LightDataChecker<E, H, Block, S>
) -> ClientResult<HashMap<Vec<u8>, Option<Vec<u8>>>> {
let child_info = match ChildType::from_prefixed_key(&request.storage_key) {
Some((ChildType::ParentKeyId, storage_key)) => ChildInfo::new_default(storage_key),
None => return Err("Invalid child type".into()),
None => return Err(ClientError::InvalidChildType),
};
read_child_proof_check::<H, _>(
convert_hash(request.header.state_root()),
remote_proof,
&child_info,
request.keys.iter(),
).map_err(Into::into)
).map_err(|e| ClientError::from(e))
}

fn check_execution_proof(
Expand Down Expand Up @@ -292,10 +292,10 @@ impl<E, Block, H, S> FetchChecker<Block> for LightDataChecker<E, H, Block, S>
if *request.header.extrinsics_root() == extrinsics_root {
Ok(body)
} else {
Err(format!("RemoteBodyRequest: invalid extrinsics root expected: {} but got {}",
*request.header.extrinsics_root(),
extrinsics_root,
).into())
Err(ClientError::ExtrinsicRootInvalid {
received: request.header.extrinsics_root().to_string(),
expected: extrinsics_root.to_string(),
})
}

}
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/light_client_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ where
let prefixed_key = PrefixedStorageKey::new_ref(&request.storage_key);
let child_info = match ChildType::from_prefixed_key(prefixed_key) {
Some((ChildType::ParentKeyId, storage_key)) => Ok(ChildInfo::new_default(storage_key)),
None => Err("Invalid child storage key".into()),
None => Err(sp_blockchain::Error::InvalidChildStorageKey),
};
let proof = match child_info.and_then(|child_info| self.chain.read_child_proof(
&BlockId::Hash(block),
Expand Down
12 changes: 6 additions & 6 deletions client/network/src/on_demand_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,47 +65,47 @@ impl<Block: BlockT> FetchChecker<Block> for AlwaysBadChecker {
_remote_header: Option<Block::Header>,
_remote_proof: StorageProof,
) -> Result<Block::Header, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
drahnr marked this conversation as resolved.
Show resolved Hide resolved
}

fn check_read_proof(
&self,
_request: &RemoteReadRequest<Block::Header>,
_remote_proof: StorageProof,
) -> Result<HashMap<Vec<u8>,Option<Vec<u8>>>, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
}

fn check_read_child_proof(
&self,
_request: &RemoteReadChildRequest<Block::Header>,
_remote_proof: StorageProof,
) -> Result<HashMap<Vec<u8>, Option<Vec<u8>>>, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
}

fn check_execution_proof(
&self,
_request: &RemoteCallRequest<Block::Header>,
_remote_proof: StorageProof,
) -> Result<Vec<u8>, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
}

fn check_changes_proof(
&self,
_request: &RemoteChangesRequest<Block::Header>,
_remote_proof: ChangesProof<Block::Header>
) -> Result<Vec<(NumberFor<Block>, u32)>, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
}

fn check_body_proof(
&self,
_request: &RemoteBodyRequest<Block::Header>,
_body: Vec<Block::Extrinsic>
) -> Result<Vec<Block::Extrinsic>, ClientError> {
Err(ClientError::Msg("AlwaysBadChecker".into()))
Err(ClientError::AlwaysBadChecker)
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/rpc-servers/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl RpcMetrics {
&["protocol"]
).ok()?, r).ok()?,
})
}).ok_or(PrometheusError::Msg("Cannot register metric".to_string()))
}).ok_or(PrometheusError::AlreadyReg)
drahnr marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading