Consistent naming for caught errors makes code easier to scan and avoids confusion in nestedDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt
Use this file to discover all available pages before exploring further.
try/catch blocks. This rule enforces a standard name (error by default) for catch parameters in try/catch clauses, promise.catch() handlers, and the rejection handler of promise.then().
| Recommended | ✅ recommended |
| Fixable | 🔧 Auto-fix |
| Suggestions | — |
Applies to
try/catchclause handlerspromise.catch(…)handlerspromise.then(onFulfilled, …)handlers
Examples
Configuration
eslint.config.js
name
Type: string — Default: 'error'
The expected name for the caught error parameter. Change this if your codebase uses a different convention.
eslint.config.js
ignore
Type: Array<string | RegExp> — Default: []
A list of patterns. Any catch parameter whose name matches one of these patterns is ignored. Strings are interpreted as regular expressions.
eslint.config.js
Ignored names
The following names are always allowed without configuration:_— but only when the error variable is never referenced.- Names that end with
errororError(for example,fsError,authError). - Names that match a pattern in the
ignoreoption.