Skip to content

Commit 9d6bec0

Browse files
drahnrBernhard Schuster
authored andcommitted
resolve unresolved error nits of paritytech#7617 (paritytech#7631)
* handle executor should_panic test better * Revert "reduce should panic, due to extended error messages" This reverts commit c080594. * remove excessive constraints * remove duplicate documentation messages for error variants * reduce T: constraints to the abs minimum * whoops * fewer bounds again Co-authored-by: Bernhard Schuster <[email protected]>
1 parent 2169c00 commit 9d6bec0

File tree

7 files changed

+46
-60
lines changed

7 files changed

+46
-60
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/consensus/slots/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ pub enum CheckedHeader<H, S> {
475475

476476
#[derive(Debug, thiserror::Error)]
477477
#[allow(missing_docs)]
478-
pub enum Error<T> where T: SlotData + Clone + Debug + Send + Sync + 'static {
478+
pub enum Error<T> where T: Debug {
479479
#[error("Slot duration is invalid: {0:?}")]
480480
SlotDurationInvalid(SlotDuration<T>),
481481
}
@@ -493,7 +493,7 @@ impl<T> Deref for SlotDuration<T> {
493493
}
494494
}
495495

496-
impl<T: SlotData + Clone> SlotData for SlotDuration<T> {
496+
impl<T: SlotData> SlotData for SlotDuration<T> {
497497
/// Get the slot duration in milliseconds.
498498
fn slot_duration(&self) -> u64
499499
where T: SlotData,

client/executor/common/src/error.rs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,75 +28,69 @@ pub type Result<T> = std::result::Result<T, Error>;
2828
#[derive(Debug, thiserror::Error)]
2929
#[allow(missing_docs)]
3030
pub enum Error {
31-
/// Unserializable Data
3231
#[error("Unserializable data encountered")]
3332
InvalidData(#[from] sp_serializer::Error),
34-
/// Trap occurred during execution
33+
3534
#[error(transparent)]
3635
Trap(#[from] wasmi::Trap),
37-
/// Wasmi loading/instantiating error
36+
3837
#[error(transparent)]
3938
Wasmi(#[from] wasmi::Error),
40-
/// Error in the API. Parameter is an error message.
39+
4140
#[error("API Error: {0}")]
4241
ApiError(String),
43-
/// Method is not found
42+
4443
#[error("Method not found: '{0}'")]
4544
MethodNotFound(String),
46-
/// Code is invalid (expected single byte)
47-
#[error("Invalid Code: '{0}'")]
45+
46+
#[error("Invalid Code (expected single byte): '{0}'")]
4847
InvalidCode(String),
49-
/// Could not get runtime version.
48+
5049
#[error("On-chain runtime does not specify version")]
5150
VersionInvalid,
52-
/// Externalities have failed.
51+
5352
#[error("Externalities error")]
5453
Externalities,
55-
/// Invalid index.
54+
5655
#[error("Invalid index provided")]
5756
InvalidIndex,
58-
/// Invalid return type.
57+
5958
#[error("Invalid type returned (should be u64)")]
6059
InvalidReturn,
61-
/// Runtime failed.
60+
6261
#[error("Runtime error")]
6362
Runtime,
64-
/// Runtime panicked.
63+
6564
#[error("Runtime panicked: {0}")]
6665
RuntimePanicked(String),
67-
/// Invalid memory reference.
66+
6867
#[error("Invalid memory reference")]
6968
InvalidMemoryReference,
70-
/// The runtime must provide a global named `__heap_base` of type i32 for specifying where the
71-
/// allocator is allowed to place its data.
72-
#[error("The runtime doesn't provide a global named `__heap_base`")]
69+
70+
#[error("The runtime doesn't provide a global named `__heap_base` of type `i32`")]
7371
HeapBaseNotFoundOrInvalid,
74-
/// The runtime WebAssembly module is not allowed to have the `start` function.
75-
#[error("The runtime has the `start` function")]
72+
73+
#[error("The runtime must not have the `start` function defined")]
7674
RuntimeHasStartFn,
77-
/// Some other error occurred
75+
7876
#[error("Other: {0}")]
7977
Other(String),
80-
/// Some error occurred in the allocator
81-
#[error("Allocation Error")]
78+
79+
#[error(transparent)]
8280
Allocator(#[from] sp_allocator::Error),
83-
/// Execution of a host function failed.
81+
8482
#[error("Host function {0} execution failed with: {1}")]
8583
FunctionExecution(String, String),
86-
/// No table is present.
87-
///
88-
/// Call was requested that requires table but none was present in the instance.
84+
8985
#[error("No table exported by wasm blob")]
9086
NoTable,
91-
/// No table entry is present.
92-
///
93-
/// Call was requested that requires specific entry in the table to be present.
87+
9488
#[error("No table entry with index {0} in wasm blob exported table")]
9589
NoTableEntryWithIndex(u32),
96-
/// Table entry is not a function.
90+
9791
#[error("Table element with index {0} is not a function in wasm blob exported table")]
9892
TableElementIsNotAFunction(u32),
99-
/// Function in table is null and thus cannot be called.
93+
10094
#[error("Table entry with index {0} in wasm blob is null")]
10195
FunctionRefIsNull(u32),
10296

client/executor/src/integration_tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ fn offchain_http_should_work(wasm_method: WasmExecutionMethod) {
523523

524524
#[test_case(WasmExecutionMethod::Interpreted)]
525525
#[cfg_attr(feature = "wasmtime", test_case(WasmExecutionMethod::Compiled))]
526-
#[should_panic]
526+
#[should_panic(expected = "Allocator ran out of space")]
527527
fn should_trap_when_heap_exhausted(wasm_method: WasmExecutionMethod) {
528528
let mut ext = TestExternalities::default();
529529

client/transaction-pool/graph/src/error.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,36 @@ pub enum Error {
3232
/// Transaction is not verifiable yet, but might be in the future.
3333
#[error("Unknown transaction validity: {0:?}")]
3434
UnknownTransaction(UnknownTransaction),
35-
/// Transaction is invalid.
35+
3636
#[error("Invalid transaction validity: {0:?}")]
3737
InvalidTransaction(InvalidTransaction),
3838
/// The transaction validity returned no "provides" tag.
3939
///
4040
/// Such transactions are not accepted to the pool, since we use those tags
4141
/// to define identity of transactions (occupance of the same "slot").
42-
#[error("The transaction does not provide any tags, so the pool can't identify it.")]
42+
#[error("The transaction validity returned no `provides` tags, so the pool can't identify it.")]
4343
NoTagsProvided,
4444

4545
#[error("Temporarily Banned")]
4646
TemporarilyBanned,
47-
/// The transaction is already in the pool.
48-
#[error("[{0:?}] Already imported")]
47+
48+
#[error("[{0:?}] Transaction is already in the pool")]
4949
AlreadyImported(Box<dyn std::any::Any + Send>),
50-
/// The transaction cannot be imported cause it's a replacement and has too low priority.
51-
#[error("Too low priority ({0} > {1})", old, new)]
50+
51+
#[error("Transaction cannot be imported due to too low priority ({0} > {1})", old, new)]
5252
TooLowPriority {
5353
/// Transaction already in the pool.
5454
old: Priority,
5555
/// Transaction entering the pool.
5656
new: Priority
5757
},
58-
/// Deps cycle detected and we couldn't import transaction.
59-
#[error("Cycle Detected")]
58+
59+
#[error("Dependency cycle detected")]
6060
CycleDetected,
61-
/// Transaction was dropped immediately after it got inserted.
61+
6262
#[error("Transaction couldn't enter the pool because of the limit.")]
6363
ImmediatelyDropped,
64-
/// Invalid block id.
64+
6565
#[error("Invlaid block id: {0}")]
6666
InvalidBlockId(String),
6767
}

primitives/allocator/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ targets = ["x86_64-unknown-linux-gnu"]
1717
sp-std = { version = "2.0.0", path = "../std", default-features = false }
1818
sp-core = { version = "2.0.0", path = "../core", default-features = false }
1919
sp-wasm-interface = { version = "2.0.0", path = "../wasm-interface", default-features = false }
20-
log = { version = "0.4.8", optional = true }
21-
derive_more = { version = "0.99.2", optional = true }
20+
log = { version = "0.4.11", optional = true }
21+
thiserror = { version = "1.0.21", optional = true }
2222

2323
[features]
2424
default = [ "std" ]
@@ -27,5 +27,5 @@ std = [
2727
"sp-core/std",
2828
"sp-wasm-interface/std",
2929
"log",
30-
"derive_more",
30+
"thiserror",
3131
]

primitives/allocator/src/error.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,15 @@
1717

1818
/// The error type used by the allocators.
1919
#[derive(sp_core::RuntimeDebug)]
20-
#[cfg_attr(feature = "std", derive(derive_more::Display))]
20+
#[cfg_attr(feature = "std", derive(thiserror::Error))]
2121
pub enum Error {
2222
/// Someone tried to allocate more memory than the allowed maximum per allocation.
23-
#[cfg_attr(feature = "std", display(fmt="Requested allocation size is too large"))]
23+
#[cfg_attr(feature = "std", error("Requested allocation size is too large"))]
2424
RequestedAllocationTooLarge,
2525
/// Allocator run out of space.
26-
#[cfg_attr(feature = "std", display(fmt="Allocator ran out of space"))]
26+
#[cfg_attr(feature = "std", error("Allocator ran out of space"))]
2727
AllocatorOutOfSpace,
2828
/// Some other error occurred.
29+
#[cfg_attr(feature = "std", error("Other: {0}"))]
2930
Other(&'static str)
3031
}
31-
32-
#[cfg(feature = "std")]
33-
impl std::error::Error for Error {
34-
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
35-
match self {
36-
_ => None,
37-
}
38-
}
39-
}

0 commit comments

Comments
 (0)