Skip to content

fix: add error handling in whitespace.js and whitespace-async.js - #3319

Open
bodapatisaikrishna wants to merge 1 commit into
airbnb:masterfrom
bodapatisaikrishna:fix/whitespace-error-handling
Open

bodapatisaikrishna wants to merge 1 commit into
airbnb:masterfrom
bodapatisaikrishna:fix/whitespace-error-handling

Conversation

@bodapatisaikrishna

Copy link
Copy Markdown

Fixes #3237.
Fixes #3238.

Summary

When ESLint 9 is used (or CLIEngine is not available):

  1. whitespace-async.js previously executed onlyErrorOnRules(...).then(...) without a .catch() handler. Any promise rejection resulted in an unhandled promise rejection and potentially non-zero output to stdout.
  2. In whitespace.js, the fallback path called JSON.parse(String(execSync(...))) with no try...catch wrapper. If the child process exited with an error or emitted non-JSON diagnostics, JSON.parse or execSync failed with an opaque error, making troubleshooting difficult.

Changes

  • Added a .catch() handler in whitespace-async.js that outputs the error to stderr and sets process.exitCode = 1.
  • Wrapped execSync and JSON.parse in whitespace.js within a try...catch block that surfaces a descriptive error including the underlying cause.
  • Applied changes to both eslint-config-airbnb-base and eslint-config-airbnb.

Verification

  • Ran Node.js syntax and integrity checks (node --check) across all modified files.

Fixes airbnb#3237.
Fixes airbnb#3238.

- In whitespace-async.js: Add .catch() handler to onlyErrorOnRules to prevent unhandled promise rejections and ensure the process exits with a non-zero exit code on failure.
- In whitespace.js: Wrap execSync and JSON.parse in try/catch to provide a descriptive error message with underlying cause when child process execution or JSON parsing fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant