Skip to content

Commit 5997825

Browse files
docs: clarify preserve-caught-error known limitation (#21294)
* docs: clarify preserve-caught-error known limitation * docs: clarify known limitation in preserve-caught-error * Update docs/src/rules/preserve-caught-error.md Co-authored-by: Francesco Trotta <[email protected]> --------- Co-authored-by: Francesco Trotta <[email protected]>
1 parent c832660 commit 5997825

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

‎docs/src/rules/preserve-caught-error.md‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -270,32 +270,32 @@ try {
270270

271271
## Known Limitations
272272

273-
This rule identifies custom error classes strictly by their name in the AST. Because it does not trace scope or type information, local shadowing will cause false positives.
273+
The `errorClassNames` option accepts names, not references to specific error classes. The rule matches these configured names in the AST and does not resolve scope or type information.
274274

275-
If a configured error class is shadowed by a local declaration, the rule will still flag it, even if the local class has a different signature and does not accept a `cause` option.
275+
As a result, a local class can shadow the intended error class while having the same name. The rule cannot distinguish the local class from the intended class and may report a false positive.
276276

277-
Example of a false positive:
277+
For example:
278278

279279
```js
280280
/* eslint preserve-caught-error: ["error", { errorClassNames: ["AppError"] }] */
281281

282282
function makeWrapped() {
283-
// Local class shadows the intended global/imported "AppError"
284-
class AppError {
285-
constructor(err) {
286-
this.original = err;
287-
}
288-
}
289-
290-
try {
291-
doSomething();
292-
} catch (err) {
293-
// Falsely reported as "missingCause" despite the local signature not accepting options
294-
throw new AppError(err);
295-
}
283+
class AppError {
284+
constructor(err) {
285+
this.original = err;
286+
}
287+
}
288+
289+
try {
290+
doSomething();
291+
} catch (err) {
292+
throw new AppError(err);
293+
}
296294
}
297295
```
298296

297+
Here, `AppError` is configured by name, but the local `AppError` class is different from the intended global/imported class. The rule still matches the name and may report a missing `cause`, even though this local class has a different constructor signature and does not accept an options object containing `cause`.
298+
299299
## When Not To Use It
300300

301301
You might not want to enable this rule if:

0 commit comments

Comments
 (0)