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: Ensure crash error messages are not duplicated #17584

Merged
merged 4 commits into from
Oct 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 15 additions & 4 deletions bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ function getErrorMessage(error) {
return util.format("%o", error);
}

/**
* Tracks error messages that are shown to the user so we only ever show the
* same message once.
* @type {Set<string>}
*/

const displayedErrors = new Set();

/**
* Catch and report unexpected error.
* @param {any} error The thrown error object.
Expand All @@ -101,14 +109,17 @@ function onFatalError(error) {
process.exitCode = 2;
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this might be a simpler approach:

if (displayedErrors.has(error) {
  return;
}
displayedErrors.add(error);


const { version } = require("../package.json");
const message = getErrorMessage(error);

console.error(`
const message = `
Oops! Something went wrong! :(

ESLint: ${version}

${message}`);
${getErrorMessage(error)}`;

if (!displayedErrors.has(message)) {
console.error(message);
displayedErrors.add(message);
}
}

//------------------------------------------------------------------------------
Expand Down