Skip to content

Commit

Permalink
fix: ShortReturn::ExpectedValue error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
csgui committed Oct 3, 2024
1 parent 65b4309 commit 5fe2a6f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions clar2wasm/src/error_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum ErrorMap {
ShortReturnAssertionFailure = 7,
ArithmeticPowError = 8,
NameAlreadyUsed = 9,
ShortReturnExpectedValue = 10,
NotMapped = 99,
}

Expand All @@ -40,6 +41,7 @@ impl From<i32> for ErrorMap {
7 => ErrorMap::ShortReturnAssertionFailure,
8 => ErrorMap::ArithmeticPowError,
9 => ErrorMap::NameAlreadyUsed,
10 => ErrorMap::ShortReturnExpectedValue,
_ => ErrorMap::NotMapped,
}
}
Expand Down Expand Up @@ -223,6 +225,10 @@ fn from_runtime_error_code(
.unwrap_or_else(|e| panic!("Could not recover arg_name: {e}"));

Error::Unchecked(CheckErrors::NameAlreadyUsed(arg_name))
},
ErrorMap::ShortReturnExpectedValue => {
Error::ShortReturn(ShortReturnType::ExpectedValue(clarity::vm::Value::UInt(42)))

}
_ => panic!("Runtime error code {} not supported", runtime_error_code),
}
Expand Down
2 changes: 1 addition & 1 deletion clar2wasm/src/wasm_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ impl WasmGenerator {
} else {
// This must be from a top-level statement, so it should cause a runtime error
builder
.i32_const(ErrorMap::ShortReturnAssertionFailure as i32)
.i32_const(ErrorMap::ShortReturnExpectedValue as i32)
.call(self.func_by_name("stdlib.runtime-error"));

builder.unreachable();
Expand Down

0 comments on commit 5fe2a6f

Please sign in to comment.