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

Not fully linked vm.Module throws errors from C++ when instantiated #18571

Closed
TimothyGu opened this issue Feb 5, 2018 · 7 comments
Closed

Not fully linked vm.Module throws errors from C++ when instantiated #18571

TimothyGu opened this issue Feb 5, 2018 · 7 comments
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. vm Issues and PRs related to the vm subsystem.

Comments

@TimothyGu
Copy link
Member

TimothyGu commented Feb 5, 2018

Executing

const neverLinked = new vm.Module('import "nonexistent";');
// Note: `await` intentionally omitted as the returned promise will never resolve.
neverLinked.link(() => new Promise(() => {}));

const main = new vm.Module('import "neverLinked";');
await main.link(() => neverLinked);
main.instantiate();

with --experimental-vm-modules throws

internal/vm/Module.js:170
    wrap.instantiate();
         ^
Error: linking error, dependency promises must be resolved on instantiate
    at Module.instantiate (internal/vm/Module.js:170:10)

which does not have the error code that is present on all other errors thrown by instantiate(). In comparison,

new vm.Module('').instantiate();

throws an error with a proper error code:

Error [ERR_VM_MODULE_NOT_LINKED]: Module must be linked before it can be instantiated

The thrown error comes from

wrap.instantiate();

which due to restrictions on how V8's C++ API operates makes it inconvenient to add the error code. The way to fix this would be to wrap a try-catch block around

wrap.instantiate();

to throw a proper errors.Error. The error message can be hard-coded as Linked dependencies must all be linked before instantiation, since this should be the only possible error thrown from this line.


See also #18106.

@TimothyGu TimothyGu added vm Issues and PRs related to the vm subsystem. errors Issues and PRs related to JavaScript errors originated in Node.js core. labels Feb 5, 2018
@TimothyGu TimothyGu self-assigned this Feb 5, 2018
@ryzokuken
Copy link
Contributor

@TimothyGu what's the status on this? Did you proceed with it?

@TimothyGu TimothyGu removed their assignment Jun 7, 2018
@TimothyGu
Copy link
Member Author

TimothyGu commented Jun 7, 2018

@ryzokuken No… Unassigning myself.

/cc @devsnek

@joyeecheung
Copy link
Member

joyeecheung commented Jun 7, 2018

There is now node_errors.h so we could also throw the error with a hard-coded message from the C++ side instead of using a try-catch hack.

@jasnell
Copy link
Member

jasnell commented Jun 25, 2020

Ping @TimothyGu ... does this need to remain open?

@TimothyGu
Copy link
Member Author

Yes. The error is the same as the OP, though the script is now

// test.js
const neverLinked = new vm.SourceTextModule('import "nonexistent";');
// Note: `await` intentionally omitted as the returned promise will never resolve.
neverLinked.link(() => new Promise(() => {}));

const main = new vm.SourceTextModule('import "neverLinked";');
await main.link(() => neverLinked);
main.instantiate();
node --experimental-vm-modules test.js

@marco-ippolito
Copy link
Member

@joyeecheung I think this issue can be closed since the vm.Module API has been changed

@legendecas
Copy link
Member

Fixed by #37598

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
errors Issues and PRs related to JavaScript errors originated in Node.js core. vm Issues and PRs related to the vm subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants