GeezerVison is showing github.com — docs: clarify preserve-caught-error known limitation (#21294) · eslint/eslint@5997825
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: docs/src/rules/preserve-caught-error.md +16-16Lines changed: 16 additions & 16 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -270,32 +270,32 @@ try { |
270 | 270 |
|
271 | 271 | ## Known Limitations |
272 | 272 |
|
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. |
274 | 274 |
|
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. |
276 | 276 |
|
277 | | -Example of a false positive: |
| 277 | +For example: |
278 | 278 |
|
279 | 279 | ```js |
280 | 280 | /* eslint preserve-caught-error: ["error", { errorClassNames: ["AppError"] }] */ |
281 | 281 |
|
282 | 282 | 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 | + } |
296 | 294 | } |
297 | 295 | ``` |
298 | 296 |
|
| 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 | + |
299 | 299 | ## When Not To Use It |
300 | 300 |
|
301 | 301 | You might not want to enable this rule if: |
|