@@ -59,7 +59,7 @@ pub enum Error {
5959 /// indicating a mismatch in function entry/exit logic.
6060 Internal ( VmInternalError ) ,
6161 Runtime ( RuntimeErrorType , Option < StackTrace > ) ,
62- ShortReturn ( ShortReturnType ) ,
62+ EarlyReturn ( EarlyReturnError ) ,
6363}
6464
6565/// Represents an internal, unrecoverable error within the Clarity VM.
@@ -148,8 +148,15 @@ pub enum RuntimeErrorType {
148148}
149149
150150#[ derive( Debug , PartialEq ) ]
151- pub enum ShortReturnType {
152- ExpectedValue ( Box < Value > ) ,
151+ /// Errors triggered during Clarity contract evaluation that cause early termination.
152+ /// These errors halt evaluation and fail the transaction.
153+ pub enum EarlyReturnError {
154+ /// Failed to unwrap an `Optional` (`none`) or `Response` (`err` or `ok`) Clarity value.
155+ /// The `Box<Value>` holds the original or thrown value. Triggered by `try!`, `unwrap-or`, or
156+ /// `unwrap-err-or`.
157+ UnwrapFailed ( Box < Value > ) ,
158+ /// An 'asserts!' expression evaluated to false.
159+ /// The `Box<Value>` holds the value provided as the second argument to `asserts!`.
153160 AssertionFailed ( Box < Value > ) ,
154161}
155162
@@ -166,7 +173,7 @@ impl PartialEq<Error> for Error {
166173 match ( self , other) {
167174 ( Error :: Runtime ( x, _) , Error :: Runtime ( y, _) ) => x == y,
168175 ( Error :: Unchecked ( x) , Error :: Unchecked ( y) ) => x == y,
169- ( Error :: ShortReturn ( x) , Error :: ShortReturn ( y) ) => x == y,
176+ ( Error :: EarlyReturn ( x) , Error :: EarlyReturn ( y) ) => x == y,
170177 ( Error :: Internal ( x) , Error :: Internal ( y) ) => x == y,
171178 _ => false ,
172179 }
@@ -252,9 +259,9 @@ impl From<(CheckErrors, &SymbolicExpression)> for Error {
252259 }
253260}
254261
255- impl From < ShortReturnType > for Error {
256- fn from ( err : ShortReturnType ) -> Self {
257- Error :: ShortReturn ( err)
262+ impl From < EarlyReturnError > for Error {
263+ fn from ( err : EarlyReturnError ) -> Self {
264+ Error :: EarlyReturn ( err)
258265 }
259266}
260267
@@ -269,11 +276,11 @@ impl From<Error> for () {
269276 fn from ( _err : Error ) -> Self { }
270277}
271278
272- impl From < ShortReturnType > for Value {
273- fn from ( val : ShortReturnType ) -> Self {
279+ impl From < EarlyReturnError > for Value {
280+ fn from ( val : EarlyReturnError ) -> Self {
274281 match val {
275- ShortReturnType :: ExpectedValue ( v) => * v,
276- ShortReturnType :: AssertionFailed ( v) => * v,
282+ EarlyReturnError :: UnwrapFailed ( v) => * v,
283+ EarlyReturnError :: AssertionFailed ( v) => * v,
277284 }
278285 }
279286}
@@ -285,15 +292,15 @@ mod test {
285292 #[ test]
286293 fn equality ( ) {
287294 assert_eq ! (
288- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) ) ,
289- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) )
295+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) ) ,
296+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
290297 ) ;
291298 assert_eq ! (
292299 Error :: Internal ( VmInternalError :: InvariantViolation ( "" . to_string( ) ) ) ,
293300 Error :: Internal ( VmInternalError :: InvariantViolation ( "" . to_string( ) ) )
294301 ) ;
295302 assert ! (
296- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) )
303+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
297304 != Error :: Internal ( VmInternalError :: InvariantViolation ( "" . to_string( ) ) )
298305 ) ;
299306 }
0 commit comments