mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 05:17:58 +00:00
Simplify runtime api error handling (#8114)
* Ahh * Work work work * Fix all the compilation errors * Fix test * More fixes...
This commit is contained in:
@@ -37,8 +37,8 @@ pub enum Error {
|
||||
#[error(transparent)]
|
||||
Wasmi(#[from] wasmi::Error),
|
||||
|
||||
#[error("API Error: {0}")]
|
||||
ApiError(String),
|
||||
#[error("Error calling api function: {0}")]
|
||||
ApiError(Box<dyn std::error::Error + Send + Sync>),
|
||||
|
||||
#[error("Method not found: '{0}'")]
|
||||
MethodNotFound(String),
|
||||
@@ -96,16 +96,16 @@ pub enum Error {
|
||||
|
||||
#[error(transparent)]
|
||||
RuntimeConstruction(#[from] WasmError),
|
||||
|
||||
|
||||
#[error("Shared memory is not supported")]
|
||||
SharedMemUnsupported,
|
||||
|
||||
|
||||
#[error("Imported globals are not supported yet")]
|
||||
ImportedGlobalsUnsupported,
|
||||
|
||||
|
||||
#[error("initializer expression can have only up to 2 expressions in wasm 1.0")]
|
||||
InitializerHasTooManyExpressions,
|
||||
|
||||
|
||||
#[error("Invalid initializer expression provided {0}")]
|
||||
InvalidInitializerExpression(String),
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeExecutor<D> {
|
||||
|
||||
fn call<
|
||||
R: Decode + Encode + PartialEq,
|
||||
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
|
||||
NC: FnOnce() -> result::Result<R, Box<dyn std::error::Error + Send + Sync>> + UnwindSafe,
|
||||
>(
|
||||
&self,
|
||||
ext: &mut dyn Externalities,
|
||||
@@ -514,7 +514,7 @@ impl<D: NativeExecutionDispatch + 'static> CodeExecutor for NativeExecutor<D> {
|
||||
let res = with_externalities_safe(&mut **ext, move || (call)())
|
||||
.and_then(|r| r
|
||||
.map(NativeOrEncoded::Native)
|
||||
.map_err(|s| Error::ApiError(s))
|
||||
.map_err(Error::ApiError)
|
||||
);
|
||||
|
||||
Ok(res)
|
||||
|
||||
@@ -414,7 +414,7 @@ mod tests {
|
||||
authoring_version: 1,
|
||||
spec_version: 1,
|
||||
impl_version: 1,
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block, Error = ()>::ID, 1)]),
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 1)]),
|
||||
};
|
||||
|
||||
let version = decode_version(&old_runtime_version.encode()).unwrap();
|
||||
@@ -429,7 +429,7 @@ mod tests {
|
||||
authoring_version: 1,
|
||||
spec_version: 1,
|
||||
impl_version: 1,
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block, Error = ()>::ID, 3)]),
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
|
||||
};
|
||||
|
||||
decode_version(&old_runtime_version.encode()).unwrap_err();
|
||||
@@ -443,7 +443,7 @@ mod tests {
|
||||
authoring_version: 1,
|
||||
spec_version: 1,
|
||||
impl_version: 1,
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block, Error = ()>::ID, 3)]),
|
||||
apis: sp_api::create_apis_vec!([(Core::<Block>::ID, 3)]),
|
||||
transaction_version: 3,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user