exceptionAssignments
Reports reassigning exception parameters in catch clauses.
✅ This rule is included in the ts logical
preset.
Reassigning an exception parameter in a catch clause can make debugging more difficult by obscuring the original error. The exception parameter contains important information about what went wrong, and reassigning it makes it harder to understand the root cause of an error.
Examples
Section titled “Examples”try { processData();} catch (error) { error = new Error("Processing failed"); throw error;}
try { validateInput();} catch (exception) { exception = null; console.log(exception);}
try { processData();} catch (error) { const wrappedError = new Error("Processing failed"); throw wrappedError;}
try { validateInput();} catch (exception) { console.log(exception.message);}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If you’re working in an existing codebase where reassigning exception parameters is an established pattern and refactoring would be too costly, you might choose to disable this rule. However, this is generally not recommended as it can make code harder to debug and maintain.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noCatchAssign
- Deno:
no-ex-assign
- ESLint:
no-ex-assign
- Oxlint:
eslint/no-ex-assign
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.