You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Uncaughtable error seems to be caughtable when it occurs inside a Promise, is that an expected behavior? #341
The uncaughtable error can be thrown by an interrupt handler.
Noticed that the fail logic of js_async_function_resume function doesn't check if an exception is caughtable before sending it to the reject function of the Promise.
An uncaughtable is an error triggered by an interrupt handler:
/* Example: using interrupt handler to limit the execution time. */staticintexec_timeout_check_handler(JSRuntime*rt, void*opaque)
{
if (timeout) return1;
return0;
}
/* ... */JS_SetInterruptHandler(rt, exec_timeout_check_handler, opaque);
When running non-async logic via JS_Call, the error won't be caught by try-catch as expected.
However, when running async logic via JS_ExecutePendingJob, the error can be caught by try-catch or Promise.catch, which will continue the logic if try-catch is used regardless of timeout.
I think we should change js_async_function_resume's return type from void to int, and return the errno other than calling the resolve funcs when JS_IsUncatchableError is true.
I think it will work in some way, but I don't think that's a complete fix. As js_async_function_resolve_call who calls js_async_function_resume always returns JS_UNDEFINED. So we should change that too.
@hongzhidao This is not the same problem. The case you mentioned in another issue is actually a normal error which is catchable if you use catch after then. However, the interruption should never be caught by design. For example, when we use interruption to check if the program cost too much resource like cpu time, we wouldn't want it to ignore the timeout regulation by catch the error. It's the same behavior for non promise operations, but it wasn't being properly implemented for promise.
Activity
XuJiandong commentedon Jan 7, 2025
it can cause this issue: #363
bnoordhuis commentedon Jan 8, 2025
Can you post a simple example and specify what you think ought to happen and what actually happens?
If this is a dup of #363, then it was fixed a few months back in quickjs-ng in quickjs-ng/quickjs@7ad9807.
laishere commentedon Jan 9, 2025
An uncaughtable is an error triggered by an interrupt handler:
When running non-async logic via
JS_Call, the error won't be caught by try-catch as expected.However, when running async logic via
JS_ExecutePendingJob, the error can be caught by try-catch or Promise.catch, which will continue the logic if try-catch is used regardless of timeout.Check the differences in the source code:
JS_CallInternal
https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs.c#L18664C10-L18664C31
js_async_function_resume
https://github.com/bellard/quickjs/blob/6e2e68fd0896957f92eb6c242a2e048c1ef3cae0/quickjs.c#L19236-L19239
I think we should change
js_async_function_resume's return type from void to int, and return the errno other than calling the resolve funcs whenJS_IsUncatchableErroris true.bnoordhuis commentedon Jan 9, 2025
Does it work with this patch applied?
(Diff against quickjs-ng; you may have to massage it a little for this repo)
laishere commentedon Jan 10, 2025
I think it will work in some way, but I don't think that's a complete fix. As
js_async_function_resolve_callwho callsjs_async_function_resumealways returnsJS_UNDEFINED. So we should change that too.I will post my test here later.
laishere commentedon Jan 10, 2025
As my project already switched to quickjs-ng, I will continue this issue there quickjs-ng/quickjs#810
Test code and solution is posted.
hongzhidao commentedon Mar 27, 2025
Hi @laishere,
It looks like not an issue.
#395
laishere commentedon Mar 27, 2025
@hongzhidao This is not the same problem. The case you mentioned in another issue is actually a normal error which is catchable if you use
catchafterthen. However, the interruption should never be caught by design. For example, when we use interruption to check if the program cost too much resource like cpu time, we wouldn't want it to ignore the timeout regulation bycatchthe error. It's the same behavior for non promise operations, but it wasn't being properly implemented for promise.hongzhidao commentedon Mar 27, 2025
Good to know, thanks.