diff --git a/crates/oxc_linter/src/rules/eslint/preserve_caught_error.rs b/crates/oxc_linter/src/rules/eslint/preserve_caught_error.rs index 1d886fd280d98..634e06458a713 100644 --- a/crates/oxc_linter/src/rules/eslint/preserve_caught_error.rs +++ b/crates/oxc_linter/src/rules/eslint/preserve_caught_error.rs @@ -187,6 +187,10 @@ impl<'a> Visit<'a> for ThrowFinder<'a, '_> { // Do not traverse into nested functions/closures within the catch block fn visit_function(&mut self, _func: &Function<'a>, _flags: ScopeFlags) {} + + // Do not traverse into nested catch clauses. They have their own caught error and will be + // analyzed separately when visiting their associated `TryStatement`. + fn visit_catch_clause(&mut self, _catch_clause: &CatchClause<'a>) {} } fn is_builtin_error_constructor(expr: &Expression, ctx: &LintContext) -> bool { @@ -407,6 +411,10 @@ fn test() { }"#, Some(serde_json::json!([{ "requireCatchParameter": false }])), ), + ( + r#"try { doSomething(); } catch (errorA) { try { doSomethingElse(); } catch (errorB) { throw new Error( `The certificate key "${chalk.yellow(keyFile)}" is invalid.\n${errorA.message}`, { cause: errorB }); } }"#, + None, + ), ]; let fail = vec![