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

🐛 BUG: Importing getPlatformProxy hijacks certain process.on events #6935

Open
rognstadragnar opened this issue Oct 9, 2024 · 2 comments
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working

Comments

@rognstadragnar
Copy link

rognstadragnar commented Oct 9, 2024

Which Cloudflare product(s) does this pertain to?

Wrangler

What version(s) of the tool(s) are you using?

3.80.2 [Wrangler]

What version of Node are you using?

22.9.0

What operating system and version are you using?

Mac Sequoia 15.0.1

Describe the Bug

Observed behavior

Simply importing getPlatformProxy from wrangler automatically adds process.on('uncaughtException', ...) and process.on('unhandledRejection', ...) listeners that re-throw . This prevents user code from handling those errors.

Expected behavior

Being able to listen to and handle these errors despite using getPlatformProxy

Explanation

Importing runtime APIs like getPlatformProxy leads to importing the code of the cli and some of that code runs on import.

From what I can tell the listeners that hijack these events stem from the yoga-layout package used within ink. The dependency is precompiled and zipped and lives inside the vendor/ directory in this repo.

The specific handlers added (wish I could point directly to the source here but it being precompiled and zipped makes that not possible):

// wrangler/wrangler-dist/cli.js:29768
process.on("uncaughtException", function(a) {
  throw a;
});
process.on(
  "unhandledRejection",
  function(a) {
    throw a;
  }
);

Re-throwing here makes all listeners added after not trigger.

Steps to reproduce

Small repro also provided below, but simply given this code:

import { getPlatformProxy } from 'wrangler';

// This line is not needed, the import alone is enough.
getPlatformProxy().then(proxy => console.log(proxy));

process.on('uncaughtException', error => {
  console.error('Oops! An uncaughtException occurred:', error);
})

process.on('unhandledRejection', error => {
  console.error('Oops! An unhandledRejection occurred:', error);
})

throw Error('This is an error');

One expects to see the error handler called. This is not the case.

<dir>/node_modules/wrangler/wrangler-dist/cli.js:29768
            throw a;
            ^

Error: This is an error
    at file:///<dir>/wrangler-repro/index.js:14:7
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:483:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)

Please provide a link to a minimal reproduction

https://github.com/rognstadragnar/cloudflare-wrangler-bug-repro

Please provide any relevant error logs

No response

@rognstadragnar rognstadragnar added the bug Something that isn't working label Oct 9, 2024
@irvinebroque
Copy link
Contributor

@rognstadragnar can you try latest wrangler with the --x-dev-env flag? Think this should address, working on resolving this one.

@emily-shen emily-shen added the awaiting reporter response Needs clarification or followup from OP label Oct 9, 2024
@rognstadragnar
Copy link
Author

@rognstadragnar can you try latest wrangler with the --x-dev-env flag? Think this should address, working on resolving this one.

As far as I can tell that flag is just a cli flag when running wrangler directly?

Maybe I wasn't quite clear but this issue is when using the getPlatformProxy api inside of node.

Let me know if I misunderstood you though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reporter response Needs clarification or followup from OP bug Something that isn't working
Projects
Status: Untriaged
Development

No branches or pull requests

3 participants