@@ -18,9 +18,29 @@ static CALL_ARGS: std::sync::Mutex<Vec<Vec<ArgType>>> = std::sync::Mutex::new(ve
18
18
fn check_exception ( this : & Ctx , err : rquickjs:: Error ) -> anyhow:: Error {
19
19
let s = match err {
20
20
rquickjs:: Error :: Exception => {
21
- let err = this. catch ( ) . into_exception ( ) . unwrap ( ) ;
22
- let msg = err. message ( ) . unwrap_or_default ( ) ;
23
- format ! ( "Exception: {}\n {}" , msg, err. stack( ) . unwrap_or_default( ) )
21
+ // Attempt to catch the exception
22
+ let exception_result = this. catch ( ) ;
23
+
24
+ // Check if we got a valid exception or if it's uninitialized (possibly due to async code)
25
+ // - https://github.com/DelSkayn/rquickjs/issues/421
26
+ // - https://github.com/DelSkayn/rquickjs/pull/422
27
+ // - https://github.com/quickjs-ng/quickjs/issues/39
28
+ // - https://github.com/quickjs-ng/quickjs/pull/1038
29
+
30
+ match exception_result. into_exception ( ) {
31
+ Some ( err) => {
32
+ let msg = err. message ( ) . unwrap_or_default ( ) ;
33
+ let stack = err. stack ( ) . unwrap_or_default ( ) ;
34
+ format ! ( "Exception: {}\n {}" , msg, stack)
35
+ }
36
+ None => {
37
+ format ! (
38
+ "Uncaught exception in async context. \
39
+ Async/Promise operations are not supported in this environment. \
40
+ Please use only synchronous code."
41
+ )
42
+ }
43
+ }
24
44
}
25
45
err => err. to_string ( ) ,
26
46
} ;
@@ -102,7 +122,7 @@ fn invoke<'a, T, F: for<'b> Fn(Ctx<'b>, Value<'b>) -> T>(
102
122
let function_invocation_result = function. call_arg ( args) ;
103
123
104
124
while ctx. execute_pending_job ( ) {
105
- continue
125
+ continue ;
106
126
}
107
127
108
128
match function_invocation_result {
0 commit comments