Skip to content

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

Closed

Description

@zhuscat

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

Activity

  1. navrocky commented on Nov 7, 2024

    @navrocky

    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.

  2. bnoordhuis commented on Nov 15, 2024

    @bnoordhuis
    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.

  3. XuJiandong commented on Jan 6, 2025

    @XuJiandong

    a very minimal reproducible case:

    ❯ cat throw.mjs
    
    throw "hi";
    
    ❯ qjs throw.mjs; echo $?
    0
    
  4. saghul commented on Jan 6, 2025

    @saghul
    Contributor

    The CLI won't exit with an error in async functions. We fixed that in NG: quickjs-ng/quickjs#514

  5. soulofmischief commented on Mar 11, 2025

    @soulofmischief

    The CLI won't exit with an error in async functions. We fixed that in NG: quickjs-ng/quickjs#514

    Thank you, I upstreamed part of that into a PR for this repository #386 but it needs review for any needed workflow changes + test if someone more familiar with the project could take on the mantle.

  6. saghul commented on Mar 12, 2025

    @saghul
    Contributor

    This project hasn't seen an update in months. Just use NG :-)

  7. soulofmischief commented on Mar 13, 2025

    @soulofmischief

    @saghul If quickjs-ng is updated to support cosmopolitan libc builds, I would definitely consider switching over. For now, only this project is already geared for it.

  8. saghul commented on Mar 13, 2025

    @saghul
    Contributor
    
    ```sh
    ./cosmocc/bin/cosmocc cutils.c libbf.c libregexp.c libunicode.c qjs.c quickjs-libc.c quickjs.c gen/standalone.c gen/repl.c -D_GNU_SOURCE -o qjs
    ```
    
  9. navrocky commented on Mar 13, 2025

    @navrocky

    I can't use quickjs-ng because it's not published on conan.io (

  10. saghul commented on Mar 13, 2025

    @saghul
    Contributor

    You can compile it yourself or use one of the prebuilt binaries.

  11. bellard commented on Mar 13, 2025

    @bellard
    Owner

    works as expected with the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions