caughtVariableNames
Enforces a consistent naming convention for catch clause error variables.
✅ This rule is included in the ts stylisticStrict presets.
Consistent naming of catch clause parameters improves code readability.
The preferred name is error, which clearly indicates the purpose of the variable.
Descriptive names ending in “Error”, are also acceptable (e.g., innerError, parseError).
Examples
Section titled “Examples”try { doSomething();} catch (e) { console.log(e);}try { readFile(path);} catch (err) { console.log(err);}try { doSomething();} catch (_) { console.log("error occurred");}try { doSomething();} catch (error) { console.log(error);}try { readFile(path);} catch (fileError) { console.log(fileError);}try { doSomething();} catch { console.log("error occurred");}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has established conventions using different names like e, err, or ex, and changing them would require significant refactoring, you may disable this rule.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- ESLint:
unicorn/catch-error-name - Oxlint:
unicorn/catch-error-name
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.