Skip to content

Honor --fail-on-error when --silent is enabled - #763

Open
ZainnQureshii wants to merge 1 commit into
meta:mainfrom
ZainnQureshii:fix/silent-fail-on-error
Open

ZainnQureshii wants to merge 1 commit into
meta:mainfrom
ZainnQureshii:fix/silent-fail-on-error

Conversation

@ZainnQureshii

Copy link
Copy Markdown

Summary

--fail-on-error has no effect when --silent is also passed: a run whose transform throws still exits 0, so a CI job or script using both flags treats the failed codemod as a success.

The cause is in src/Runner.js. The failOnError exit check sits inside the if (!options.silent) block that prints the summary, so silent mode skips it along with the output:

if (!options.silent) {
  process.stdout.write('All done. \n');
  // ...stats...
  if (options.failOnError && fileCounters.error > 0) {
    process.exit(1);
  }
}

The error count is still kept in silent mode (fileCounters is updated by the worker messages regardless of silent), so the fix moves the existing check out of the output block and leaves everything else as it was. The --fail-on-error help text in bin/jscodeshift.js describes a non-zero exit on errors with no exception for silent mode, and in the review of #416, which added the flag, its author noted that the check "didn't really belong in the if (!options.silent) { statement".

Tests

New CLI cases in bin/__tests__/jscodeshift-test.js spawn the real binary, with and without --run-in-band:

  • a throwing transform with --fail-on-error exits 1, both without and with --silent
  • a successful transform with --silent --fail-on-error prints nothing to stdout and exits 0
  • a throwing transform with --silent and no --fail-on-error still exits 0

The small change to the run() helper passes the child's exit code through so the tests can read it.

Before the fix, the two --silent=true error cases fail (Expected: 1, Received: 0), one per worker mode; after it, all eight pass. The full yarn test suite passes.

A patch changeset is included.

Separately, the --silent help text says "do not write to stdout or stderr", but transform errors are still printed in silent mode (log.error in src/Runner.js checks only verbose), and the error tests above rely on that output. This PR leaves that behaviour and the help text alone.

Prepared with AI assistance (Claude Code) and reviewed with GitHub Copilot.

🤖 Generated with Claude Code

The failOnError exit check sat inside the if (!options.silent) block that prints the run summary, so a silent run whose transform threw still exited 0. Move the check after the output block; error counting already happens in silent mode.
@changeset-bot

changeset-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 406710f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jscodeshift Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 10, 2026

Copy link
Copy Markdown

@ZainnQureshii is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed label Nov 10, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant