close

catch-error-name

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/catch-error-name': 'error',
    },
  },
]);

Rule Details

Enforce a specific parameter name in catch clauses and Promise rejection handlers.

Consistent error names make handlers easier to scan. The default name is error; descriptive names ending in error or Error are accepted, as are names matching an ignore pattern. An unused _ parameter is also accepted. The rule can automatically rename the declaration and all references, appending underscores when necessary to avoid shadowing.

Examples of incorrect code for this rule:

try {} catch (badName) {}
promise.catch(badName => {});
promise.then(undefined, badName => {});

Examples of correct code for this rule:

try {} catch (error) {}
promise.catch(error => {});
promise.then(undefined, error => {});
try {} catch (fsError) {}

Options

  • name (string, default: "error") sets the expected name.
  • ignore (string[], default: []) contains JavaScript regular-expression patterns to ignore.

Differences from ESLint

When an unused handler parameter would be renamed to the same name as a direct lexical declaration in the handler body, rslint appends an underscore. ESLint currently emits a fix that creates a duplicate binding and invalid syntax in this case.

Original Documentation