Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error showed when error threw with --module flag #363

Open
zhuscat opened this issue Oct 30, 2024 · 2 comments
Open

No error showed when error threw with --module flag #363

zhuscat opened this issue Oct 30, 2024 · 2 comments

Comments

@zhuscat
Copy link

zhuscat commented Oct 30, 2024

QuickJS Version: 2024-01-13

/* fib module */
export function fib(n)
{
    if (n <= 0)
        return 0;
    else if (n == 1)
        return 1;
    else
        return fib(n - 1) + fib(n - 2);
}
/* example of JS module */

import { fib } from "./fib_module.js";

// here I throw an Error
throw new Error('test error');

console.log("Hello World");
console.log("fib(10)=", fib(10));

When I execute qjs ./examples/hello_module.js, no error showed

@navrocky
Copy link

navrocky commented Nov 7, 2024

I confirm this error for a version 2024-01-13. After rolling back to version 2023-12-09 the errors started to appear.

I am using the QuickJS API, not the CLI. When I call JS_Eval with a broken script and JS_EVAL_TYPE_GLOBAL flag then it returns JS exception (it's normal):

JS_Eval(ctx, script.c_str(), script.size(), file.c_str(), JS_EVAL_TYPE_GLOBAL);

But if I use the JS_EVAL_TYPE_MODULE flag then JS_Eval silently terminates without any errors or exceptions and returns JSValue with JS_TAG_MODULE:

JS_Eval(ctx, script.c_str(), script.size(), file.c_str(), JS_EVAL_TYPE_MODULE);

Logging insertions into the script shows that execution flow aborted right at the point of the error.

In version 2023-12-09 everything works with modules as expected.

@bnoordhuis
Copy link
Contributor

Does it work when you pass the JS_Eval result to JS_EvalFunction? And in turn pass that result to js_std_await?

I didn't test with the code from this repo but in quickjs-ng it works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants