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

Clarity-Wasm: add error mapping for already used arg error #5192

Merged
merged 2 commits into from
Sep 16, 2024
Merged
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
31 changes: 31 additions & 0 deletions clarity/src/vm/clarity_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7647,6 +7647,7 @@ mod tests {
mod error_mapping {
use wasmtime::{AsContextMut, Instance, Trap};

use super::read_identifier_from_wasm;
use crate::vm::errors::{CheckErrors, Error, RuntimeErrorType, ShortReturnType, WasmError};
use crate::vm::types::ResponseData;
use crate::vm::Value;
Expand All @@ -7666,6 +7667,7 @@ mod error_mapping {
Panic = 6,
ShortReturnAssertionFailure = 7,
ArithmeticPowError = 8,
NameAlreadyUsed = 9,
NotMapped = 99,
}

Expand All @@ -7682,6 +7684,7 @@ mod error_mapping {
6 => ErrorMap::Panic,
7 => ErrorMap::ShortReturnAssertionFailure,
8 => ErrorMap::ArithmeticPowError,
9 => ErrorMap::NameAlreadyUsed,
_ => ErrorMap::NotMapped,
}
}
Expand Down Expand Up @@ -7804,6 +7807,34 @@ mod error_mapping {
RuntimeErrorType::Arithmetic(POW_ERROR_MESSAGE.into()),
Some(Vec::new()),
),
ErrorMap::NameAlreadyUsed => {
let runtime_error_arg_offset = instance
.get_global(&mut store, "runtime-error-arg-offset")
.and_then(|glob| glob.get(&mut store).i32())
.unwrap_or_else(|| {
panic!("Could not find $runtime-error-arg-offset global with i32 value")
});

let runtime_error_arg_len = instance
.get_global(&mut store, "runtime-error-arg-len")
.and_then(|glob| glob.get(&mut store).i32())
.unwrap_or_else(|| {
panic!("Could not find $runtime-error-arg-len global with i32 value")
});

let memory = instance
.get_memory(&mut store, "memory")
.unwrap_or_else(|| panic!("Could not find wasm instance memory"));
let arg_name = read_identifier_from_wasm(
memory,
&mut store,
runtime_error_arg_offset,
runtime_error_arg_len,
)
.unwrap_or_else(|e| panic!("Could not recover arg_name: {e}"));

Error::Unchecked(CheckErrors::NameAlreadyUsed(arg_name))
}
_ => panic!("Runtime error code {} not supported", runtime_error_code),
}
}
Expand Down
Loading