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(plugin-workspace-tools): properly report errors for all non-zero exit codes #6535

Merged
merged 2 commits into from
Nov 22, 2024
Merged
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
24 changes: 24 additions & 0 deletions .yarn/versions/30ae755e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/plugin-workspace-tools": 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/builder"
- "@yarnpkg/core"
- "@yarnpkg/doctor"
- "@yarnpkg/pnp"
16 changes: 9 additions & 7 deletions packages/plugin-workspace-tools/sources/commands/foreach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export default class WorkspacesForeachCommand extends BaseCommand {
needsProcessing.delete(identHash);
processing.delete(workspace.anchoredDescriptor.descriptorHash);

return exitCode;
return {workspace, exitCode};
}));

// If we're not executing processes in parallel we can just wait for it
Expand All @@ -424,13 +424,15 @@ export default class WorkspacesForeachCommand extends BaseCommand {
return;
}

const exitCodes: Array<number> = await Promise.all(commandPromises);
const errorCode = exitCodes.find(code => code !== 0);
const results: Array<{ workspace: Workspace, exitCode: number }> = await Promise.all(commandPromises);
results.forEach(({workspace, exitCode}) => {
if (exitCode !== 0) {
report.reportError(MessageName.UNNAMED, `The command failed in workspace ${structUtils.prettyLocator(configuration, workspace.anchoredLocator)} with exit code ${exitCode}`);
}
});

// The order in which the exit codes will be processed is fairly
// opaque, so better just return a generic "1" for determinism.
if (finalExitCode === null)
finalExitCode = typeof errorCode !== `undefined` ? 1 : finalExitCode;
Copy link
Contributor Author

@kumavis kumavis Oct 3, 2024

Choose a reason for hiding this comment

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

we no longer need to set the finalExitCode here bc the resulting error code will be set to 1 by report.exitCode() since errors have been reported.

exitCode() {
return this.hasErrors() ? 1 : 0;
}

const exitCodes = results.map(result => result.exitCode);
const errorCode = exitCodes.find(code => code !== 0);

if ((this.topological || this.topologicalDev) && typeof errorCode !== `undefined`) {
report.reportError(MessageName.UNNAMED, `The command failed for workspaces that are depended upon by other workspaces; can't satisfy the dependency graph`);
Expand Down
Loading