Simplify runtime api error handling (#8114)

* Ahh

* Work work work

* Fix all the compilation errors

* Fix test

* More fixes...
This commit is contained in:
Bastian Köcher
2021-02-15 12:55:40 +01:00
committed by GitHub
parent b5e692104c
commit 33f9becf41
48 changed files with 270 additions and 415 deletions
@@ -1,19 +0,0 @@
use substrate_test_runtime_client::runtime::Block;
sp_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
}
struct MockApi;
sp_api::mock_impl_runtime_apis! {
impl Api<Block> for MockApi {
type OtherData = u32;
fn test(data: u64) {}
}
}
fn main() {}
@@ -1,5 +0,0 @@
error: Only associated type with name `Error` is allowed
--> $DIR/mock_only_error_associated_type.rs:13:3
|
13 | type OtherData = u32;
| ^^^^
@@ -1,29 +0,0 @@
use substrate_test_runtime_client::runtime::Block;
sp_api::decl_runtime_apis! {
pub trait Api {
fn test(data: u64);
}
pub trait Api2 {
fn test(data: u64);
}
}
struct MockApi;
sp_api::mock_impl_runtime_apis! {
impl Api<Block> for MockApi {
type Error = u32;
fn test(data: u64) {}
}
impl Api2<Block> for MockApi {
type Error = u64;
fn test(data: u64) {}
}
}
fn main() {}
@@ -1,29 +0,0 @@
error: Error type can not change between runtime apis
--> $DIR/mock_only_one_error_type.rs:23:3
|
23 | type Error = u64;
| ^^^^
error: First error type was declared here.
--> $DIR/mock_only_one_error_type.rs:17:16
|
17 | type Error = u32;
| ^^^
error[E0277]: the trait bound `u32: From<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ApiError>` is not satisfied
--> $DIR/mock_only_one_error_type.rs:17:16
|
17 | type Error = u32;
| ^^^ the trait `From<sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ApiError>` is not implemented for `u32`
|
::: $WORKSPACE/primitives/api/src/lib.rs
|
| type Error: std::fmt::Debug + From<ApiError>;
| -------------- required by this bound in `sp_api_hidden_includes_DECL_RUNTIME_APIS::sp_api::ApiErrorExt::Error`
|
= help: the following implementations were found:
<u32 as From<HttpError>>
<u32 as From<HttpRequestId>>
<u32 as From<HttpRequestStatus>>
<u32 as From<Ipv4Addr>>
and 18 others