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

fix(cli): simplify empty event loop handling #6402

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .yarn/versions/3829ec64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
releases:
"@yarnpkg/cli": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ module.exports = {
});

await expect(run(`install`)).rejects.toMatchObject({
code: 42,
stdout: expect.stringContaining(`Yarn is terminating due to an unexpected empty event loop`),
code: 1,
stderr: expect.stringContaining(`Yarn is terminating due to an unexpected empty event loop`),
});
}),
);
Expand Down
7 changes: 1 addition & 6 deletions packages/yarnpkg-cli/sources/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,12 @@ export async function runExit(argv: Array<string>, {cwd = ppath.cwd(), selfPath,
const cli = getBaseCli({cwd, pluginConfiguration});

function unexpectedTerminationHandler() {
Cli.defaultContext.stdout.write(`ERROR: Yarn is terminating due to an unexpected empty event loop.\nPlease report this issue at https://github.com/yarnpkg/berry/issues.`);
throw new Error(`Yarn is terminating due to an unexpected empty event loop.\nPlease report this issue at https://github.com/yarnpkg/berry/issues`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the stacktrace matter? Wouldn't the only useful information be the place the aborted async operation was started (which we can't get anyway)?

Copy link
Member Author

@merceyz merceyz Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user wants to locate the file, other than that it doesn't provide much, it's more to let Node.js do the error handling.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to keep the output clean; at least something like this, similar to what we do in the catch?

Suggested change
throw new Error(`Yarn is terminating due to an unexpected empty event loop.\nPlease report this issue at https://github.com/yarnpkg/berry/issues`);
Cli.defaultContext.stdout.write(cli.error(new UsageError(`Yarn is terminating due to an unexpected empty event loop.\nPlease report this issue at https://github.com/yarnpkg/berry/issues`)));
process.exitCode = 1;

}

process.once(`beforeExit`, unexpectedTerminationHandler);

try {
// The exit code is set to an error code before the CLI runs so that
// if the event loop becomes empty and node terminates without
// finishing the execution of this function it counts as an error.
// https://github.com/yarnpkg/berry/issues/6398
process.exitCode = 42;
process.exitCode = await run(cli, argv, {selfPath, pluginConfiguration});
} catch (error) {
Cli.defaultContext.stdout.write(cli.error(error));
Expand Down
Loading