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 e6a2288
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 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 @@ -224,6 +226,9 @@ fn from_runtime_error_code(

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),
}
}
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 e6a2288

Please sign in to comment.