# preserve-caught-error

Rule `eslint/preserve-caught-error`. Disallow losing originally caught error when re-throwing custom errors

- Source: eslint
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 183M weekly downloads of presets that enable it
- Trend: +26.8% last quarter
- Rank: #86 by reach, #1359 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `preserve-caught-error` | yes | suggestion | package `eslint` | [docs](https://eslint.org/docs/latest/rules/preserve-caught-error) |
| Oxlint | `preserve-caught-error` | no | safe | plugin `eslint`, category suspicious | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/preserve-caught-error.html) |
| Biome | `style/useErrorCause` | no | no | group style, since 2.3.12 | [docs](https://biomejs.dev/linter/rules/use-error-cause/) |

## Code examples

### Incorrect: the rule reports this

```js
// Not using the `cause` option
try {
    // ...
} catch (error) {
    throw new Error("Something went wrong: " + error.message);
}

// Throwing a new Error with unrelated cause
try {
  doSomething();
} catch (err) {
  const unrelated = new Error("other");
  throw new Error("Something failed", { cause: unrelated });
}

// Caught error is being lost partially due to destructuring
try {
  doSomething();
} catch ({ message, ...rest }) {
  throw new Error(message);
}

// Cause error is being shadowed by a closer scoped redeclaration.
try {
    doSomething();
} catch (error) {
    if (whatever) {
        const error = anotherError; // This declaration is the problem.
        throw new Error("Something went wrong", { cause: error });
    }
}
```

### Correct: the rule accepts this

```js
try {
    // ...
} catch (error) {
    throw new Error("Something went wrong", { cause: error });
}

// When the thrown error is not directly related to the caught error.
try {
} catch (error) {
  foo = {
    bar() {
      // This throw is not directly related to the caught error.
      throw new Error("Something went wrong");
    }
  };
}

// No throw inside catch
try {
    doSomething();
} catch (e) {
    console.error(e);
}

// Ignoring the caught error at the parameter level
// This is valid by default, but this behavior can be changed
// by using the `requireCatchParameter` option discussed below.
try {
  doSomething();
} catch {
  throw new TypeError("Something went wrong");
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "preserve-caught-error": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "preserve-caught-error": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useErrorCause": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [ESLint recommended](https://lintradar.dev/presets/eslint-recommended.md) | ESLint | `@eslint/js` | 64 | 178.8M | +25.9% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [Nuxt](https://lintradar.dev/presets/nuxt.md) | ESLint | `@nuxt/eslint-config` | 188 | 1.5M | +72.8% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [eslint/prefer-spread](https://lintradar.dev/rules/eslint/prefer-spread.md): Require spread operators instead of `.apply()`
- [eslint/no-undef](https://lintradar.dev/rules/eslint/no-undef.md): Disallow the use of undeclared variables unless mentioned in `/*global */` comments
- [eslint/no-var](https://lintradar.dev/rules/eslint/no-var.md): Require `let` or `const` instead of `var`
- [eslint/no-empty](https://lintradar.dev/rules/eslint/no-empty.md): Disallow empty block statements
- [eslint/no-unexpected-multiline](https://lintradar.dev/rules/eslint/no-unexpected-multiline.md): Disallow confusing multiline expressions
- [eslint/no-useless-assignment](https://lintradar.dev/rules/eslint/no-useless-assignment.md): Disallow variable assignments when the value is not used

---

Web page: https://lintradar.dev/rules/eslint/preserve-caught-error. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
