@@ -46,7 +46,7 @@ pub enum Error {
4646 Unchecked ( CheckErrors ) ,
4747 Interpreter ( InterpreterError ) ,
4848 Runtime ( RuntimeErrorType , Option < StackTrace > ) ,
49- ShortReturn ( ShortReturnType ) ,
49+ EarlyReturn ( EarlyReturnError ) ,
5050}
5151
5252/// InterpreterErrors are errors that *should never* occur.
@@ -104,8 +104,15 @@ pub enum RuntimeErrorType {
104104}
105105
106106#[ derive( Debug , PartialEq ) ]
107- pub enum ShortReturnType {
108- ExpectedValue ( Box < Value > ) ,
107+ /// Errors triggered during Clarity contract evaluation that cause early termination.
108+ /// These errors halt evaluation and fail the transaction.
109+ pub enum EarlyReturnError {
110+ /// Failed to unwrap an `Optional` (`none`) or `Response` (`err` or `ok`) Clarity value.
111+ /// The `Box<Value>` holds the original or thrown value. Triggered by `try!`, `unwrap-or`, or
112+ /// `unwrap-err-or`.
113+ UnwrapFailed ( Box < Value > ) ,
114+ /// An 'asserts!' expression evaluated to false.
115+ /// The `Box<Value>` holds the value provided as the second argument to `asserts!`.
109116 AssertionFailed ( Box < Value > ) ,
110117}
111118
@@ -122,7 +129,7 @@ impl PartialEq<Error> for Error {
122129 match ( self , other) {
123130 ( Error :: Runtime ( x, _) , Error :: Runtime ( y, _) ) => x == y,
124131 ( Error :: Unchecked ( x) , Error :: Unchecked ( y) ) => x == y,
125- ( Error :: ShortReturn ( x) , Error :: ShortReturn ( y) ) => x == y,
132+ ( Error :: EarlyReturn ( x) , Error :: EarlyReturn ( y) ) => x == y,
126133 ( Error :: Interpreter ( x) , Error :: Interpreter ( y) ) => x == y,
127134 _ => false ,
128135 }
@@ -208,9 +215,9 @@ impl From<(CheckErrors, &SymbolicExpression)> for Error {
208215 }
209216}
210217
211- impl From < ShortReturnType > for Error {
212- fn from ( err : ShortReturnType ) -> Self {
213- Error :: ShortReturn ( err)
218+ impl From < EarlyReturnError > for Error {
219+ fn from ( err : EarlyReturnError ) -> Self {
220+ Error :: EarlyReturn ( err)
214221 }
215222}
216223
@@ -225,11 +232,11 @@ impl From<Error> for () {
225232 fn from ( _err : Error ) -> Self { }
226233}
227234
228- impl From < ShortReturnType > for Value {
229- fn from ( val : ShortReturnType ) -> Self {
235+ impl From < EarlyReturnError > for Value {
236+ fn from ( val : EarlyReturnError ) -> Self {
230237 match val {
231- ShortReturnType :: ExpectedValue ( v) => * v,
232- ShortReturnType :: AssertionFailed ( v) => * v,
238+ EarlyReturnError :: UnwrapFailed ( v) => * v,
239+ EarlyReturnError :: AssertionFailed ( v) => * v,
233240 }
234241 }
235242}
@@ -241,15 +248,15 @@ mod test {
241248 #[ test]
242249 fn equality ( ) {
243250 assert_eq ! (
244- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) ) ,
245- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) )
251+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) ) ,
252+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
246253 ) ;
247254 assert_eq ! (
248255 Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) ) ,
249256 Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) )
250257 ) ;
251258 assert ! (
252- Error :: ShortReturn ( ShortReturnType :: ExpectedValue ( Box :: new( Value :: Bool ( true ) ) ) )
259+ Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
253260 != Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) )
254261 ) ;
255262 }
0 commit comments