Skip to content

About error handling in custom module loader #848

Closed

Description

@Icemic

Hello, I want to know that how to deal with errors (such as invalid path, file busy, etc.) inside module loader.

Since it is defined as

typedef JSModuleDef *JSModuleLoaderFunc(JSContext *ctx, const char *module_name, void *opaque);

is it right to return nullptr when some error occurs? I've tried before calling JS_LoadModule, which returned a promise rejection as expected.

And what about JSModuleNormalizeFunc?

Activity

  1. saghul commented on Jan 24, 2025

    @saghul
    Contributor

    is it right to return nullptr when some error occurs?

    Yes, you should throw an exception and return NULL. I recently added some error handling for similar cases (when setting the meta object fails): ab48ede

    And what about JSModuleNormalizeFunc?

    Same thing. The default one can also fail in case of memory errors for example, and it will simply return NULL with the OOM exception thrown.

  2. locked and limited conversation to collaborators on Jan 24, 2025
  3. converted this issue into a discussion #849 on Jan 24, 2025
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