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

Commit fec0e49

Browse files
authored
introduce errors with info (#1834)
1 parent 5649229 commit fec0e49

File tree

58 files changed

+1984
-2031
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1984
-2031
lines changed

Cargo.lock

Lines changed: 58 additions & 290 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,12 @@ wasm-opt = false
1414
crate-type = ["cdylib", "rlib"]
1515

1616
[dependencies]
17-
log = "0.4.8"
18-
futures = { version = "0.3.4", features = ["compat"] }
19-
structopt = "0.3.8"
20-
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
17+
log = "0.4.11"
18+
structopt = { version = "0.3.8", optional = true }
2119
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
22-
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
23-
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
24-
sc-client-db = { git = "https://github.com/paritytech/substrate", branch = "master" }
25-
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "master" }
2620
sc-tracing = { git = "https://github.com/paritytech/substrate", branch = "master" }
2721
service = { package = "polkadot-service", path = "../node/service", default-features = false, optional = true }
2822

29-
tokio = { version = "0.2.13", features = ["rt-threaded"], optional = true }
3023
frame-benchmarking-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
3124
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
3225
sc-service = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true }
@@ -46,7 +39,7 @@ default = [ "wasmtime", "db", "cli", "full-node", "trie-memory-tracker" ]
4639
wasmtime = [ "sc-cli/wasmtime" ]
4740
db = [ "service/db" ]
4841
cli = [
49-
"tokio",
42+
"structopt",
5043
"sc-cli",
5144
"sc-service",
5245
"frame-benchmarking-cli",

cli/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
//! Polkadot CLI library.
1818
1919
#![warn(missing_docs)]
20-
#![warn(unused_extern_crates)]
2120

2221
#[cfg(feature = "browser")]
2322
mod browser;

erasure-coding/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ reed_solomon = { package = "reed-solomon-erasure", version = "4.0.2"}
1010
codec = { package = "parity-scale-codec", version = "1.3.4", default-features = false, features = ["derive"] }
1111
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
1212
trie = { package = "sp-trie", git = "https://github.com/paritytech/substrate", branch = "master" }
13-
derive_more = "0.15.0"
13+
thiserror = "1.0.21"

erasure-coding/src/lib.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use primitives::v0::{self, Hash as H256, BlakeTwo256, HashT};
3030
use primitives::v1;
3131
use sp_core::Blake2Hasher;
3232
use trie::{EMPTY_PREFIX, MemoryDB, Trie, TrieMut, trie_types::{TrieDBMut, TrieDB}};
33+
use thiserror::Error;
3334

3435
use self::wrapped_shard::WrappedShard;
3536

@@ -39,35 +40,43 @@ mod wrapped_shard;
3940
const MAX_VALIDATORS: usize = <galois_16::Field as reed_solomon::Field>::ORDER;
4041

4142
/// Errors in erasure coding.
42-
#[derive(Debug, Clone, PartialEq, derive_more::Display)]
43+
#[derive(Debug, Clone, PartialEq, Error)]
4344
pub enum Error {
4445
/// Returned when there are too many validators.
46+
#[error("There are too many validators")]
4547
TooManyValidators,
4648
/// Cannot encode something for no validators
49+
#[error("Validator set is empty")]
4750
EmptyValidators,
4851
/// Cannot reconstruct: wrong number of validators.
52+
#[error("Validator count mismatches between encoding and decoding")]
4953
WrongValidatorCount,
5054
/// Not enough chunks present.
55+
#[error("Not enough chunks to reconstruct message")]
5156
NotEnoughChunks,
5257
/// Too many chunks present.
58+
#[error("Too many chunks present")]
5359
TooManyChunks,
5460
/// Chunks not of uniform length or the chunks are empty.
61+
#[error("Chunks are not unform, mismatch in length or are zero sized")]
5562
NonUniformChunks,
5663
/// An uneven byte-length of a shard is not valid for GF(2^16) encoding.
64+
#[error("Uneven length is not valid for field GF(2^16)")]
5765
UnevenLength,
5866
/// Chunk index out of bounds.
59-
#[display(fmt = "Chunk is out of bounds: {} {}", _0, _1)]
60-
ChunkIndexOutOfBounds(usize, usize),
67+
#[error("Chunk is out of bounds: {chunk_index} not included in 0..{n_validators}")]
68+
ChunkIndexOutOfBounds{ chunk_index: usize, n_validators: usize },
6169
/// Bad payload in reconstructed bytes.
70+
#[error("Reconstructed payload invalid")]
6271
BadPayload,
6372
/// Invalid branch proof.
73+
#[error("Invalid branch proof")]
6474
InvalidBranchProof,
6575
/// Branch out of bounds.
76+
#[error("Branch is out of bounds")]
6677
BranchOutOfBounds,
6778
}
6879

69-
impl std::error::Error for Error { }
70-
7180
#[derive(Debug, PartialEq)]
7281
struct CodeParams {
7382
data_shards: usize,
@@ -206,7 +215,7 @@ fn reconstruct<'a, I: 'a, T: Decode>(n_validators: usize, chunks: I) -> Result<T
206215
let mut shard_len = None;
207216
for (chunk_data, chunk_idx) in chunks.into_iter().take(n_validators) {
208217
if chunk_idx >= n_validators {
209-
return Err(Error::ChunkIndexOutOfBounds(chunk_idx, n_validators));
218+
return Err(Error::ChunkIndexOutOfBounds{ chunk_index: chunk_idx, n_validators });
210219
}
211220

212221
let shard_len = shard_len.get_or_insert_with(|| chunk_data.len());

node/collation-generation/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ authors = ["Parity Technologies <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
derive_more = "0.99.9"
98
futures = "0.3.5"
109
log = "0.4.8"
1110
polkadot-erasure-coding = { path = "../../erasure-coding" }
@@ -14,6 +13,7 @@ polkadot-node-subsystem = { path = "../subsystem" }
1413
polkadot-node-subsystem-util = { path = "../subsystem-util" }
1514
polkadot-primitives = { path = "../../primitives" }
1615
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
16+
thiserror = "1.0.21"
1717

1818
[dev-dependencies]
1919
polkadot-node-subsystem-test-helpers = { path = "../subsystem-test-helpers" }

node/collation-generation/src/error.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use thiserror::Error;
1718

18-
#[derive(Debug, derive_more::From)]
19+
#[derive(Debug, Error)]
1920
pub enum Error {
20-
#[from]
21-
Subsystem(polkadot_node_subsystem::SubsystemError),
22-
#[from]
23-
OneshotRecv(futures::channel::oneshot::Canceled),
24-
#[from]
25-
Runtime(polkadot_node_subsystem::errors::RuntimeApiError),
26-
#[from]
27-
Util(polkadot_node_subsystem_util::Error),
28-
#[from]
29-
Erasure(polkadot_erasure_coding::Error),
21+
#[error(transparent)]
22+
Subsystem(#[from] polkadot_node_subsystem::SubsystemError),
23+
#[error(transparent)]
24+
OneshotRecv(#[from] futures::channel::oneshot::Canceled),
25+
#[error(transparent)]
26+
Runtime(#[from] polkadot_node_subsystem::errors::RuntimeApiError),
27+
#[error(transparent)]
28+
Util(#[from] polkadot_node_subsystem_util::Error),
29+
#[error(transparent)]
30+
Erasure(#[from] polkadot_erasure_coding::Error),
3031
}
3132

3233
pub type Result<T> = std::result::Result<T, Error>;

node/core/av-store/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ authors = ["Parity Technologies <[email protected]>"]
55
edition = "2018"
66

77
[dependencies]
8-
derive_more = "0.99.9"
98
futures = "0.3.5"
109
futures-timer = "3.0.2"
1110
kvdb = "0.7.0"
1211
kvdb-rocksdb = "0.9.1"
13-
log = "0.4.8"
12+
log = "0.4.11"
13+
thiserror = "1.0.21"
1414

1515
codec = { package = "parity-scale-codec", version = "1.3.1", features = ["derive"] }
1616
erasure = { package = "polkadot-erasure-coding", path = "../../../erasure-coding" }

node/core/av-store/src/lib.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use polkadot_node_subsystem_util::metrics::{self, prometheus};
4444
use polkadot_subsystem::messages::{
4545
AllMessages, AvailabilityStoreMessage, ChainApiMessage, RuntimeApiMessage, RuntimeApiRequest,
4646
};
47+
use thiserror::Error;
4748

4849
const LOG_TARGET: &str = "availability";
4950

@@ -53,22 +54,22 @@ mod columns {
5354
pub const NUM_COLUMNS: u32 = 2;
5455
}
5556

56-
#[derive(Debug, derive_more::From)]
57+
#[derive(Debug, Error)]
5758
enum Error {
58-
#[from]
59-
Chain(ChainApiError),
60-
#[from]
61-
Erasure(erasure::Error),
62-
#[from]
63-
Io(io::Error),
64-
#[from]
65-
Oneshot(oneshot::Canceled),
66-
#[from]
67-
Runtime(RuntimeApiError),
68-
#[from]
69-
Subsystem(SubsystemError),
70-
#[from]
71-
Time(SystemTimeError),
59+
#[error(transparent)]
60+
RuntimeAPI(#[from] RuntimeApiError),
61+
#[error(transparent)]
62+
ChainAPI(#[from] ChainApiError),
63+
#[error(transparent)]
64+
Erasure(#[from] erasure::Error),
65+
#[error(transparent)]
66+
Io(#[from] io::Error),
67+
#[error(transparent)]
68+
Oneshot(#[from] oneshot::Canceled),
69+
#[error(transparent)]
70+
Subsystem(#[from] SubsystemError),
71+
#[error(transparent)]
72+
Time(#[from] SystemTimeError),
7273
}
7374

7475
/// A wrapper type for delays.

node/core/backing/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@ edition = "2018"
66

77
[dependencies]
88
futures = "0.3.5"
9-
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
109
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
11-
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
12-
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
1310
polkadot-primitives = { path = "../../../primitives" }
1411
polkadot-node-primitives = { path = "../../primitives" }
1512
polkadot-subsystem = { package = "polkadot-node-subsystem", path = "../../subsystem" }
1613
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
1714
erasure-coding = { package = "polkadot-erasure-coding", path = "../../../erasure-coding" }
1815
statement-table = { package = "polkadot-statement-table", path = "../../../statement-table" }
19-
derive_more = "0.99.9"
2016
bitvec = { version = "0.17.4", default-features = false, features = ["alloc"] }
21-
log = "0.4.8"
17+
log = "0.4.11"
18+
thiserror = "1.0.21"
2219

2320
[dev-dependencies]
2421
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }

node/core/backing/src/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
//! Implements a `CandidateBackingSubsystem`.
1818
19+
#![deny(unused_crate_dependencies)]
20+
1921
use std::collections::{HashMap, HashSet};
2022
use std::convert::TryFrom;
2123
use std::pin::Pin;
@@ -64,22 +66,26 @@ use statement_table::{
6466
SignedStatement as TableSignedStatement, Summary as TableSummary,
6567
},
6668
};
69+
use thiserror::Error;
6770

68-
#[derive(Debug, derive_more::From)]
71+
#[derive(Debug, Error)]
6972
enum Error {
73+
#[error("Candidate is not found")]
7074
CandidateNotFound,
75+
#[error("Signature is invalid")]
7176
InvalidSignature,
72-
StoreFailed,
73-
#[from]
74-
Erasure(erasure_coding::Error),
75-
#[from]
76-
ValidationFailed(ValidationFailed),
77-
#[from]
78-
Oneshot(oneshot::Canceled),
79-
#[from]
80-
Mpsc(mpsc::SendError),
81-
#[from]
82-
UtilError(util::Error),
77+
#[error("Failed to send candidates {0:?}")]
78+
Send(Vec<NewBackedCandidate>),
79+
#[error("Oneshot never resolved")]
80+
Oneshot(#[from] #[source] oneshot::Canceled),
81+
#[error("Obtaining erasure chunks failed")]
82+
ObtainErasureChunks(#[from] #[source] erasure_coding::Error),
83+
#[error(transparent)]
84+
ValidationFailed(#[from] ValidationFailed),
85+
#[error(transparent)]
86+
Mpsc(#[from] mpsc::SendError),
87+
#[error(transparent)]
88+
UtilError(#[from] util::Error),
8389
}
8490

8591
/// Holds all data needed for candidate backing job operation.
@@ -468,7 +474,7 @@ impl CandidateBackingJob {
468474
CandidateBackingMessage::GetBackedCandidates(_, tx) => {
469475
let backed = self.get_backed();
470476

471-
tx.send(backed).map_err(|_| oneshot::Canceled)?;
477+
tx.send(backed).map_err(|data| Error::Send(data))?;
472478
}
473479
}
474480

@@ -640,7 +646,7 @@ impl CandidateBackingJob {
640646
)
641647
).await?;
642648

643-
rx.await?.map_err(|_| Error::StoreFailed)?;
649+
let _ = rx.await?;
644650

645651
Ok(())
646652
}

node/core/bitfield-signing/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ edition = "2018"
66

77
[dependencies]
88
bitvec = "0.17.4"
9-
derive_more = "0.99.9"
109
futures = "0.3.5"
11-
log = "0.4.8"
10+
log = "0.4.11"
1211
polkadot-primitives = { path = "../../../primitives" }
1312
polkadot-node-subsystem = { path = "../../subsystem" }
1413
polkadot-node-subsystem-util = { path = "../../subsystem-util" }
1514
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master" }
1615
wasm-timer = "0.2.4"
16+
thiserror = "1.0.21"

0 commit comments

Comments
 (0)