Skip to content

feat: add preserve-caught-error rule for ESLint >= 9.35.0#530

Closed
Rei-x with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-529
Closed

feat: add preserve-caught-error rule for ESLint >= 9.35.0#530
Rei-x with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-529

Conversation

Copilot AI commented Sep 11, 2025

Copy link
Copy Markdown
Contributor

This PR implements the new ESLint rule preserve-caught-error that was introduced in ESLint v9.35.0. The rule enforces adding a cause property when rethrowing errors to preserve the original error context.

What this PR does

  • Conditionally enables the rule: Only applies preserve-caught-error when ESLint version is >= 9.35.0, ensuring backward compatibility
  • Proper version detection: Uses semver to check the installed ESLint version at runtime
  • Graceful fallback: Handles cases where ESLint package information is unavailable

Implementation details

The rule is added to the JavaScript configuration in src/eslint/configs/javascript.ts with version checking:

// Check if ESLint version is >= 9.35.0 to enable preserve-caught-error rule
const eslintInfo = await getPackageInfo("eslint");
const supportsPreserveCaughtError = 
  eslintInfo?.version !== undefined && semver.gte(eslintInfo.version, "9.35.0");

// Conditionally add the rule
...(supportsPreserveCaughtError ? { "preserve-caught-error": "error" } : {}),

Rule behavior

The preserve-caught-error rule will now catch patterns like:

// ❌ This will trigger an error
try {
  throw new Error("Original error");
} catch (error) {
  throw new Error("New error without cause"); // Missing cause
}

// ✅ This is correct
try {
  throw new Error("Original error");
} catch (error) {
  throw new Error("New error with cause", { cause: error }); // Preserves context
}

Testing

  • Added comprehensive unit tests covering different ESLint version scenarios
  • Verified manual functionality with test files
  • All existing tests continue to pass
  • Linting and build processes work correctly

Fixes #529.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Nowy rule - obowiązkowy cause przed rethrowowaniu błędu feat: add preserve-caught-error rule for ESLint >= 9.35.0 Sep 11, 2025
Copilot AI requested a review from Rei-x September 11, 2025 09:42
@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/Solvro/lib-web-solvro-config/@solvro/config@530

commit: af01ce0

@kguzek kguzek added the wontfix This will not be worked on label Mar 9, 2026
@kguzek

kguzek commented Mar 9, 2026

Copy link
Copy Markdown
Member

zbyt ambitne

@kguzek kguzek closed this Mar 9, 2026
@kguzek
kguzek deleted the copilot/fix-529 branch March 16, 2026 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L wontfix This will not be worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nowy rule - obowiązkowy cause przed rethrowowaniu błędu

3 participants