Skip to content

Commit 98076ca

Browse files
authored
Merge pull request #5309 from stacks-network/fix-error-map
fix: correct error mapping for BadTypeConstruction
2 parents f6f2a01 + e3130e2 commit 98076ca

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

clarity/src/vm/clarity_wasm.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7674,18 +7674,53 @@ mod error_mapping {
76747674
const SQRTI_ERROR_MESSAGE: &str = "sqrti must be passed a positive integer";
76757675
const POW_ERROR_MESSAGE: &str = "Power argument to (pow ...) must be a u32 integer";
76767676

7677+
/// Represents various error conditions that can occur
7678+
/// during Clarity contract execution
7679+
/// or other Stacks blockchain operations.
7680+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
76777681
pub enum ErrorMap {
7682+
/// Indicates that the error is not related to Clarity contract execution.
76787683
NotClarityError = -1,
7684+
7685+
/// Represents an arithmetic overflow error in Clarity contract execution.
7686+
/// This occurs when a calculation exceeds the maximum value representable.
76797687
ArithmeticOverflow = 0,
7688+
7689+
/// Represents an arithmetic underflow error in Clarity contract execution.
7690+
/// This occurs when a calculation results in a value below the minimum representable value.
76807691
ArithmeticUnderflow = 1,
7692+
7693+
/// Indicates an attempt to divide by zero in a Clarity contract.
76817694
DivisionByZero = 2,
7695+
7696+
/// Represents an error in calculating the logarithm base 2 in a Clarity contract.
7697+
/// This could occur for negative inputs.
76827698
ArithmeticLog2Error = 3,
7699+
7700+
/// Represents an error in calculating the integer square root in a Clarity contract.
7701+
/// This could occur for negative inputs.
76837702
ArithmeticSqrtiError = 4,
7684-
UnwrapFailure = 5,
7703+
7704+
/// Indicates an error in constructing a type, possibly due to invalid parameters.
7705+
BadTypeConstruction = 5,
7706+
7707+
/// Represents a deliberate panic in contract execution,
7708+
/// usually triggered by `(unwrap-panic...)` and `(unwrap-err-panic...)`.
76857709
Panic = 6,
7710+
7711+
/// Indicates a failure in an assertion that was expected to cause a short return,
7712+
/// usually triggered by `(asserts!...)`.
76867713
ShortReturnAssertionFailure = 7,
7714+
7715+
/// Represents an error in exponentiation operations in a Clarity contract.
7716+
/// This could occur for invalid bases or exponents.
76877717
ArithmeticPowError = 8,
7718+
7719+
/// Indicates an attempt to use a name that is already in use, possibly for a variable or function.
76887720
NameAlreadyUsed = 9,
7721+
7722+
/// A catch-all for errors that are not mapped to specific error codes.
7723+
/// This might be used for unexpected or unclassified errors.
76897724
NotMapped = 99,
76907725
}
76917726

@@ -7698,7 +7733,7 @@ mod error_mapping {
76987733
2 => ErrorMap::DivisionByZero,
76997734
3 => ErrorMap::ArithmeticLog2Error,
77007735
4 => ErrorMap::ArithmeticSqrtiError,
7701-
5 => ErrorMap::UnwrapFailure,
7736+
5 => ErrorMap::BadTypeConstruction,
77027737
6 => ErrorMap::Panic,
77037738
7 => ErrorMap::ShortReturnAssertionFailure,
77047739
8 => ErrorMap::ArithmeticPowError,
@@ -7806,8 +7841,8 @@ mod error_mapping {
78067841
RuntimeErrorType::Arithmetic(SQRTI_ERROR_MESSAGE.into()),
78077842
Some(Vec::new()),
78087843
),
7809-
ErrorMap::UnwrapFailure => {
7810-
Error::Runtime(RuntimeErrorType::UnwrapFailure, Some(Vec::new()))
7844+
ErrorMap::BadTypeConstruction => {
7845+
Error::Runtime(RuntimeErrorType::BadTypeConstruction, Some(Vec::new()))
78117846
}
78127847
ErrorMap::Panic => {
78137848
// TODO: see issue: #531

0 commit comments

Comments
 (0)