Skip to content

Fix: ESLint 9+ path: handle child script errors in whitespace-async.js#3239

Open
dataCenter430 wants to merge 1 commit intoairbnb:masterfrom
dataCenter430:fix/handle-child-script-errors-in-whitespace-async
Open

Fix: ESLint 9+ path: handle child script errors in whitespace-async.js#3239
dataCenter430 wants to merge 1 commit intoairbnb:masterfrom
dataCenter430:fix/handle-child-script-errors-in-whitespace-async

Conversation

@dataCenter430
Copy link

Summary

When CLIEngine is not available (ESLint 9+), whitespace.js loads config by running whitespace-async.js with execSync and parsing its stdout as JSON. The async script had no .catch() on its promise, so rejections became unhandled: the child could exit non-zero and print to stderr while the parent received empty or partial stdout and failed with a generic JSON.parse error, hiding the real failure.

Approach

  • Do not add try/catch in whitespace.js; errors should still crash.
  • Fix the child script so the ESLint 9/10 path fails in a clear, diagnosable way.

Changes

  • packages/eslint-config-airbnb-base/whitespace-async.js: Add .catch() so that on rejection we log the error to stderr and process.exit(1).
  • packages/eslint-config-airbnb/whitespace-async.js: Same change.

On success, only JSON is written to stdout, so the parent’s execSync + JSON.parse continues to work. On failure, the real error goes to stderr and the process exits 1, so execSync throws and the thrown error includes the child’s stderr, making the root cause visible without masking crashes.

Fixes #3238

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No error handling around execSync + JSON.parse in whitespace.js (ESLint 9 path)

1 participant