mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 07:37:57 +00:00
chore/error: remove from str conversion and add deprecation notificat… (#7472)
* chore/error: remove from str conversion and add deprecation notifications * fixup changes * fix test looking for gone ::Msg variant * another test fix * one is duplicate, the other is not, so duplicates reported are n-1 * darn spaces Co-authored-by: Andronik Ordian <write@reusable.software> * remove pointless doc comments of error variants without any value * low hanging fruits (for a tall person) * moar error type variants * avoid the storage modules for now They are in need of a refactor, and the pain is rather large removing all String error and DefaultError occurences. * chore remove pointless error generic * fix test for mocks, add a bunch of non_exhaustive * max line width * test fixes due to error changes * fin * error outputs... again * undo stderr adjustments * Update client/consensus/slots/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * remove closure clutter Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * more error types * introduce ApiError * extract Mock error * ApiError refactor * even more error types * the last for now * chore unused deps * another extraction * reduce should panic, due to extended error messages * error test happiness * shift error lines by one * doc tests * white space Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Into -> From Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * remove pointless codec Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * avoid pointless self import Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> Co-authored-by: Bernhard Schuster <bernhard@parity.io> Co-authored-by: Andronik Ordian <write@reusable.software> Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
6722a83ba6
commit
8c7d217091
@@ -25,92 +25,95 @@ use wasmi;
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Error type.
|
||||
#[derive(Debug, derive_more::Display, derive_more::From)]
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum Error {
|
||||
/// Unserializable Data
|
||||
InvalidData(sp_serializer::Error),
|
||||
#[error("Unserializable data encountered")]
|
||||
InvalidData(#[from] sp_serializer::Error),
|
||||
/// Trap occurred during execution
|
||||
Trap(wasmi::Trap),
|
||||
#[error(transparent)]
|
||||
Trap(#[from] wasmi::Trap),
|
||||
/// Wasmi loading/instantiating error
|
||||
Wasmi(wasmi::Error),
|
||||
#[error(transparent)]
|
||||
Wasmi(#[from] wasmi::Error),
|
||||
/// Error in the API. Parameter is an error message.
|
||||
#[from(ignore)]
|
||||
#[error("API Error: {0}")]
|
||||
ApiError(String),
|
||||
/// Method is not found
|
||||
#[display(fmt="Method not found: '{}'", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Method not found: '{0}'")]
|
||||
MethodNotFound(String),
|
||||
/// Code is invalid (expected single byte)
|
||||
#[display(fmt="Invalid Code: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Invalid Code: '{0}'")]
|
||||
InvalidCode(String),
|
||||
/// Could not get runtime version.
|
||||
#[display(fmt="On-chain runtime does not specify version")]
|
||||
#[error("On-chain runtime does not specify version")]
|
||||
VersionInvalid,
|
||||
/// Externalities have failed.
|
||||
#[display(fmt="Externalities error")]
|
||||
#[error("Externalities error")]
|
||||
Externalities,
|
||||
/// Invalid index.
|
||||
#[display(fmt="Invalid index provided")]
|
||||
#[error("Invalid index provided")]
|
||||
InvalidIndex,
|
||||
/// Invalid return type.
|
||||
#[display(fmt="Invalid type returned (should be u64)")]
|
||||
#[error("Invalid type returned (should be u64)")]
|
||||
InvalidReturn,
|
||||
/// Runtime failed.
|
||||
#[display(fmt="Runtime error")]
|
||||
#[error("Runtime error")]
|
||||
Runtime,
|
||||
/// Runtime panicked.
|
||||
#[display(fmt="Runtime panicked: {}", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Runtime panicked: {0}")]
|
||||
RuntimePanicked(String),
|
||||
/// Invalid memory reference.
|
||||
#[display(fmt="Invalid memory reference")]
|
||||
#[error("Invalid memory reference")]
|
||||
InvalidMemoryReference,
|
||||
/// The runtime must provide a global named `__heap_base` of type i32 for specifying where the
|
||||
/// allocator is allowed to place its data.
|
||||
#[display(fmt="The runtime doesn't provide a global named `__heap_base`")]
|
||||
#[error("The runtime doesn't provide a global named `__heap_base`")]
|
||||
HeapBaseNotFoundOrInvalid,
|
||||
/// The runtime WebAssembly module is not allowed to have the `start` function.
|
||||
#[display(fmt="The runtime has the `start` function")]
|
||||
#[error("The runtime has the `start` function")]
|
||||
RuntimeHasStartFn,
|
||||
/// Some other error occurred
|
||||
#[error("Other: {0}")]
|
||||
Other(String),
|
||||
/// Some error occurred in the allocator
|
||||
#[display(fmt="Error in allocator: {}", _0)]
|
||||
Allocator(sp_allocator::Error),
|
||||
#[error("Allocation Error")]
|
||||
Allocator(#[from] sp_allocator::Error),
|
||||
/// Execution of a host function failed.
|
||||
#[display(fmt="Host function {} execution failed with: {}", _0, _1)]
|
||||
#[error("Host function {0} execution failed with: {1}")]
|
||||
FunctionExecution(String, String),
|
||||
/// No table is present.
|
||||
///
|
||||
/// Call was requested that requires table but none was present in the instance.
|
||||
#[display(fmt="No table exported by wasm blob")]
|
||||
#[error("No table exported by wasm blob")]
|
||||
NoTable,
|
||||
/// No table entry is present.
|
||||
///
|
||||
/// Call was requested that requires specific entry in the table to be present.
|
||||
#[display(fmt="No table entry with index {} in wasm blob exported table", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("No table entry with index {0} in wasm blob exported table")]
|
||||
NoTableEntryWithIndex(u32),
|
||||
/// Table entry is not a function.
|
||||
#[display(fmt="Table element with index {} is not a function in wasm blob exported table", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Table element with index {0} is not a function in wasm blob exported table")]
|
||||
TableElementIsNotAFunction(u32),
|
||||
/// Function in table is null and thus cannot be called.
|
||||
#[display(fmt="Table entry with index {} in wasm blob is null", _0)]
|
||||
#[from(ignore)]
|
||||
#[error("Table entry with index {0} in wasm blob is null")]
|
||||
FunctionRefIsNull(u32),
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
||||
match self {
|
||||
Error::InvalidData(ref err) => Some(err),
|
||||
Error::Trap(ref err) => Some(err),
|
||||
Error::Wasmi(ref err) => Some(err),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
#[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),
|
||||
}
|
||||
|
||||
impl wasmi::HostError for Error {}
|
||||
@@ -121,9 +124,9 @@ impl From<&'static str> for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WasmError> for Error {
|
||||
fn from(err: WasmError) -> Error {
|
||||
Error::Other(err.to_string())
|
||||
impl From<String> for Error {
|
||||
fn from(err: String) -> Error {
|
||||
Error::Other(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,3 +154,5 @@ pub enum WasmError {
|
||||
/// Other error happenend.
|
||||
Other(String),
|
||||
}
|
||||
|
||||
impl std::error::Error for WasmError {}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
//! A set of common definitions that are needed for defining execution engines.
|
||||
|
||||
#![warn(missing_docs)]
|
||||
#![deny(unused_crate_dependencies)]
|
||||
|
||||
pub mod error;
|
||||
pub mod sandbox;
|
||||
|
||||
@@ -87,15 +87,12 @@ impl DataSegmentsSnapshot {
|
||||
let init_expr = match segment.offset() {
|
||||
Some(offset) => offset.code(),
|
||||
// Return if the segment is passive
|
||||
None => return Err(Error::from("Shared memory is not supported".to_string())),
|
||||
None => return Err(Error::SharedMemUnsupported),
|
||||
};
|
||||
|
||||
// [op, End]
|
||||
if init_expr.len() != 2 {
|
||||
return Err(Error::from(
|
||||
"initializer expression can have only up to 2 expressions in wasm 1.0"
|
||||
.to_string(),
|
||||
));
|
||||
return Err(Error::InitializerHasTooManyExpressions);
|
||||
}
|
||||
let offset = match &init_expr[0] {
|
||||
Instruction::I32Const(v) => *v as u32,
|
||||
@@ -106,15 +103,10 @@ impl DataSegmentsSnapshot {
|
||||
// At the moment of writing the Substrate Runtime Interface does not provide
|
||||
// any globals. There is nothing that prevents us from supporting this
|
||||
// if/when we gain those.
|
||||
return Err(Error::from(
|
||||
"Imported globals are not supported yet".to_string(),
|
||||
));
|
||||
return Err(Error::ImportedGlobalsUnsupported);
|
||||
}
|
||||
insn => {
|
||||
return Err(Error::from(format!(
|
||||
"{:?} is not supported as initializer expression in wasm 1.0",
|
||||
insn
|
||||
)))
|
||||
return Err(Error::InvalidInitializerExpression(format!("{:?}", insn)))
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user