@@ -38,14 +38,30 @@ pub struct IncomparableError<T> {
3838 pub err : T ,
3939}
4040
41+ /// Errors that can occur during the runtime execution of Clarity contracts in the virtual machine.
42+ /// These encompass type-checking failures, interpreter issues, runtime errors, and premature returns.
43+ /// Unlike static analysis errors in `ClarityError::StaticCheck(CheckError)` or `ClarityError::Parse(ParseError)`,
44+ /// which are caught before execution during type-checking or parsing, these errors occur during dynamic
45+ /// evaluation and may involve conditions not detectable statically, such as dynamically constructed expressions
46+ /// (e.g., based on VRF seeds or runtime data).
4147#[ derive( Debug ) ]
42- pub enum Error {
43- /// UncheckedErrors are errors that *should* be caught by the
44- /// TypeChecker and other check passes. Test executions may
45- /// trigger these errors.
48+ pub enum VmExecutionError {
49+ /// Type-checking errors caught during runtime analysis, which should typically be detected by
50+ /// static type-checking passes before execution. These may occur in test executions or when
51+ /// dynamic expression construction (e.g., using runtime data like VRF seeds) creates structures
52+ /// violating type or resource constraints (e.g., excessive stack depth).
53+ /// The `CheckErrorKind` wraps the specific type-checking error encountered at runtime.
4654 Unchecked ( CheckErrorKind ) ,
4755 Interpreter ( InterpreterError ) ,
56+ /// Errors that occur during runtime execution of Clarity code, such as arithmetic errors or
57+ /// invalid operations, expected as part of contract evaluation.
58+ /// The `RuntimeErrorType` wraps the specific runtime error, and the `Option<StackTrace>` provides
59+ /// an optional stack trace for debugging, if available.
4860 Runtime ( RuntimeErrorType , Option < StackTrace > ) ,
61+ /// Errors triggered during Clarity contract evaluation that cause early termination with
62+ /// insufficient results (e.g., unwrapping an empty `Option`).
63+ /// The `EarlyReturnError` wraps the specific early return condition, detailing the premature
64+ /// termination cause.
4965 EarlyReturn ( EarlyReturnError ) ,
5066}
5167
@@ -116,30 +132,30 @@ pub enum EarlyReturnError {
116132 AssertionFailed ( Box < Value > ) ,
117133}
118134
119- pub type InterpreterResult < R > = Result < R , Error > ;
135+ pub type InterpreterResult < R > = Result < R , VmExecutionError > ;
120136
121137impl < T > PartialEq < IncomparableError < T > > for IncomparableError < T > {
122138 fn eq ( & self , _other : & IncomparableError < T > ) -> bool {
123139 false
124140 }
125141}
126142
127- impl PartialEq < Error > for Error {
128- fn eq ( & self , other : & Error ) -> bool {
143+ impl PartialEq < VmExecutionError > for VmExecutionError {
144+ fn eq ( & self , other : & VmExecutionError ) -> bool {
129145 match ( self , other) {
130- ( Error :: Runtime ( x, _) , Error :: Runtime ( y, _) ) => x == y,
131- ( Error :: Unchecked ( x) , Error :: Unchecked ( y) ) => x == y,
132- ( Error :: EarlyReturn ( x) , Error :: EarlyReturn ( y) ) => x == y,
133- ( Error :: Interpreter ( x) , Error :: Interpreter ( y) ) => x == y,
146+ ( VmExecutionError :: Runtime ( x, _) , VmExecutionError :: Runtime ( y, _) ) => x == y,
147+ ( VmExecutionError :: Unchecked ( x) , VmExecutionError :: Unchecked ( y) ) => x == y,
148+ ( VmExecutionError :: EarlyReturn ( x) , VmExecutionError :: EarlyReturn ( y) ) => x == y,
149+ ( VmExecutionError :: Interpreter ( x) , VmExecutionError :: Interpreter ( y) ) => x == y,
134150 _ => false ,
135151 }
136152 }
137153}
138154
139- impl fmt:: Display for Error {
155+ impl fmt:: Display for VmExecutionError {
140156 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
141157 match self {
142- Error :: Runtime ( err, stack) => {
158+ VmExecutionError :: Runtime ( err, stack) => {
143159 write ! ( f, "{err}" ) ?;
144160 if let Some ( stack_trace) = stack {
145161 writeln ! ( f, "\n Stack Trace: " ) ?;
@@ -160,7 +176,7 @@ impl fmt::Display for RuntimeErrorType {
160176 }
161177}
162178
163- impl error:: Error for Error {
179+ impl error:: Error for VmExecutionError {
164180 fn source ( & self ) -> Option < & ( dyn error:: Error + ' static ) > {
165181 None
166182 }
@@ -172,64 +188,64 @@ impl error::Error for RuntimeErrorType {
172188 }
173189}
174190
175- impl From < ParseError > for Error {
191+ impl From < ParseError > for VmExecutionError {
176192 fn from ( err : ParseError ) -> Self {
177193 match * err. err {
178- ParseErrors :: InterpreterFailure => Error :: from ( InterpreterError :: Expect (
194+ ParseErrors :: InterpreterFailure => VmExecutionError :: from ( InterpreterError :: Expect (
179195 "Unexpected interpreter failure during parsing" . into ( ) ,
180196 ) ) ,
181- _ => Error :: from ( RuntimeErrorType :: ASTError ( Box :: new ( err) ) ) ,
197+ _ => VmExecutionError :: from ( RuntimeErrorType :: ASTError ( Box :: new ( err) ) ) ,
182198 }
183199 }
184200}
185201
186- impl From < CostErrors > for Error {
202+ impl From < CostErrors > for VmExecutionError {
187203 fn from ( err : CostErrors ) -> Self {
188204 match err {
189- CostErrors :: InterpreterFailure => Error :: from ( InterpreterError :: Expect (
205+ CostErrors :: InterpreterFailure => VmExecutionError :: from ( InterpreterError :: Expect (
190206 "Interpreter failure during cost calculation" . into ( ) ,
191207 ) ) ,
192- CostErrors :: Expect ( s) => Error :: from ( InterpreterError :: Expect ( format ! (
208+ CostErrors :: Expect ( s) => VmExecutionError :: from ( InterpreterError :: Expect ( format ! (
193209 "Interpreter failure during cost calculation: {s}"
194210 ) ) ) ,
195- other_err => Error :: from ( CheckErrorKind :: from ( other_err) ) ,
211+ other_err => VmExecutionError :: from ( CheckErrorKind :: from ( other_err) ) ,
196212 }
197213 }
198214}
199215
200- impl From < RuntimeErrorType > for Error {
216+ impl From < RuntimeErrorType > for VmExecutionError {
201217 fn from ( err : RuntimeErrorType ) -> Self {
202- Error :: Runtime ( err, None )
218+ VmExecutionError :: Runtime ( err, None )
203219 }
204220}
205221
206- impl From < CheckErrorKind > for Error {
222+ impl From < CheckErrorKind > for VmExecutionError {
207223 fn from ( err : CheckErrorKind ) -> Self {
208- Error :: Unchecked ( err)
224+ VmExecutionError :: Unchecked ( err)
209225 }
210226}
211227
212- impl From < ( CheckErrorKind , & SymbolicExpression ) > for Error {
228+ impl From < ( CheckErrorKind , & SymbolicExpression ) > for VmExecutionError {
213229 fn from ( err : ( CheckErrorKind , & SymbolicExpression ) ) -> Self {
214- Error :: Unchecked ( err. 0 )
230+ VmExecutionError :: Unchecked ( err. 0 )
215231 }
216232}
217233
218- impl From < EarlyReturnError > for Error {
234+ impl From < EarlyReturnError > for VmExecutionError {
219235 fn from ( err : EarlyReturnError ) -> Self {
220- Error :: EarlyReturn ( err)
236+ VmExecutionError :: EarlyReturn ( err)
221237 }
222238}
223239
224- impl From < InterpreterError > for Error {
240+ impl From < InterpreterError > for VmExecutionError {
225241 fn from ( err : InterpreterError ) -> Self {
226- Error :: Interpreter ( err)
242+ VmExecutionError :: Interpreter ( err)
227243 }
228244}
229245
230246#[ cfg( any( test, feature = "testing" ) ) ]
231- impl From < Error > for ( ) {
232- fn from ( _err : Error ) -> Self { }
247+ impl From < VmExecutionError > for ( ) {
248+ fn from ( _err : VmExecutionError ) -> Self { }
233249}
234250
235251impl From < EarlyReturnError > for Value {
@@ -248,16 +264,23 @@ mod test {
248264 #[ test]
249265 fn equality ( ) {
250266 assert_eq ! (
251- Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) ) ,
252- Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
267+ VmExecutionError :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool (
268+ true
269+ ) ) ) ) ,
270+ VmExecutionError :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool (
271+ true
272+ ) ) ) )
253273 ) ;
254274 assert_eq ! (
255- Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) ) ,
256- Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) )
275+ VmExecutionError :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) ) ,
276+ VmExecutionError :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) )
257277 ) ;
258278 assert ! (
259- Error :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool ( true ) ) ) )
260- != Error :: Interpreter ( InterpreterError :: InterpreterError ( "" . to_string( ) ) )
279+ VmExecutionError :: EarlyReturn ( EarlyReturnError :: UnwrapFailed ( Box :: new( Value :: Bool (
280+ true
281+ ) ) ) ) != VmExecutionError :: Interpreter ( InterpreterError :: InterpreterError (
282+ "" . to_string( )
283+ ) )
261284 ) ;
262285 }
263286}
0 commit comments