diff --git a/clarity/src/vm/clarity_wasm.rs b/clarity/src/vm/clarity_wasm.rs index e92f9d6858..7883c08859 100644 --- a/clarity/src/vm/clarity_wasm.rs +++ b/clarity/src/vm/clarity_wasm.rs @@ -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; @@ -7666,6 +7667,7 @@ mod error_mapping { Panic = 6, ShortReturnAssertionFailure = 7, ArithmeticPowError = 8, + NameAlreadyUsed = 9, NotMapped = 99, } @@ -7682,6 +7684,7 @@ mod error_mapping { 6 => ErrorMap::Panic, 7 => ErrorMap::ShortReturnAssertionFailure, 8 => ErrorMap::ArithmeticPowError, + 9 => ErrorMap::NameAlreadyUsed, _ => ErrorMap::NotMapped, } } @@ -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), } }