Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: streamline contract caching code #7851

Merged
merged 8 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 12 additions & 31 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@ use std::io;
///
/// See the doc comment on `VMResult` for an explanation what the difference
/// between this and a `FunctionCallError` is.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum VMRunnerError {
/// An error that is caused by an operation on an inconsistent state.
/// E.g. an integer overflow by using a value from the given context.
#[error("{0}")]
InconsistentStateError(InconsistentStateError),
/// Error caused by caching.
CacheError(CacheError),
#[error("cache error: {0}")]
CacheError(#[from] CacheError),
/// Error (eg, resource exhausting) when loading a successfully compiled
/// contract into executable memory.
#[error("loading error: {0}")]
LoadingError(String),
/// Type erased error from `External` trait implementation.
#[error("external error")]
ExternalError(AnyError),
/// Non-deterministic error.
#[error("non-deterministic error during contract execution: {0}")]
Nondeterministic(String),
WasmUnknownError {
debug_message: String,
},
/// Error when requiring an unavailable feature of the WASM compiler.
///
/// The only place this gets emitted today is when calling `precompile`
/// in wasmtime runner.
UnsupportedCompiler {
debug_message: String,
},
#[error("unknown error during contract execution: {debug_message}")]
WasmUnknownError { debug_message: String },
}

/// Permitted errors that cause a function call to fail gracefully.
Expand Down Expand Up @@ -416,25 +416,6 @@ impl fmt::Display for MethodResolveError {
}
}

impl fmt::Display for VMRunnerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
VMRunnerError::ExternalError(_err) => write!(f, "Serialized ExternalError"),
VMRunnerError::InconsistentStateError(err) => fmt::Display::fmt(err, f),
VMRunnerError::CacheError(err) => write!(f, "Cache error: {:?}", err),
VMRunnerError::WasmUnknownError { debug_message } => {
write!(f, "Unknown error during Wasm contract execution: {}", debug_message)
}
VMRunnerError::Nondeterministic(msg) => {
write!(f, "Nondeterministic error during contract execution: {}", msg)
}
VMRunnerError::UnsupportedCompiler { debug_message } => {
write!(f, "Unsupported compiler: {debug_message}")
}
}
}
}

impl std::fmt::Display for InconsistentStateError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
match self {
Expand Down
Loading