{"record":{"id":"a4537db296851c5e","repo":"oxc-project/oxc","slug":"the-catch-parameter-caught-ident-should-be-nam","errorCode":null,"errorMessage":"The catch parameter {caught_ident:?} should be named {expected_name:?}","messagePattern":"The catch parameter (.+?) should be named (.+?)","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/catch_error_name.rs","lineNumber":27,"sourceCode":"use oxc_span::Span;\nuse oxc_str::CompactStr;\nuse oxc_syntax::identifier::is_identifier_name;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::deserialize_regex_vec,\n};\n\nfn catch_error_name_diagnostic(\n    caught_ident: &str,\n    expected_name: &str,\n    span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"The catch parameter {caught_ident:?} should be named {expected_name:?}\"\n    ))\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct CatchErrorName(Box<CatchErrorNameConfig>);\n\n#[derive(Debug, Clone, Deserialize, JsonSchema)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct CatchErrorNameConfig {\n    /// A list of patterns to ignore when checking `catch` variable names. The pattern\n    /// can be a string or regular expression.\n    #[serde(default, deserialize_with = \"deserialize_regex_vec\")]\n    ignore: Vec<Regex>,\n    /// The name to use for error variables in `catch` blocks. You can customize it\n    /// to something other than `'error'` (e.g., `'exception'`).\n    #[serde(default = \"default_error_name\", deserialize_with = \"deserialize_error_name\")]","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/catch_error_name.rs#L9-L45","documentation":"Diagnostic from oxlint's `unicorn/catch-error-name` rule. It enforces one consistent, descriptive name for caught errors (default `error`) across `try/catch` bindings, `promise.catch(...)` callbacks, and `promise.then(undefined, ...)` rejection handlers. The message uses Rust debug formatting, so the names render quoted: `The catch parameter \"err\" should be named \"error\"`. A binding named `_` is tolerated when it is never referenced, and names whose lowercase form ends with the configured name are accepted.","triggerScenarios":"Any used catch or rejection-callback parameter whose name differs from the configured `name` (default `error`) and does not match an `ignore` pattern — e.g. `try { ... } catch (err) { console.log(err) }` or `promise.catch(e => ...)`. Also fires when the name is not even an identifier-shaped string after the rule's normalization.","commonSituations":"Codebases that historically use `e`, `err`, or `ex`; enabling the `unicorn` preset for the first time; refactors that renamed error parameters inconsistently; teams standardizing on `exception` via the `name` option.","solutions":["Rename the parameter to `error` — `oxlint --fix` applies it automatically.","Standardize on a different name by setting the rule's `name` option (e.g. \"exception\") in .oxlintrc.json.","Whitelist legacy names with the `ignore` option (strings or regexes), e.g. [\"^e$\", \"^err$\"].","If the error object is unused, switch to the optional catch binding `catch {}` or keep `_` unreferenced."],"exampleFix":"// before\ntry {\n  save();\n} catch (err) {\n  console.error(err);\n}\n// after\ntry {\n  save();\n} catch (error) {\n  console.error(error);\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — align the rule with your convention before enabling the unicorn preset\n{\n  \"rules\": {\n    \"unicorn/catch-error-name\": [\"warn\", { \"name\": \"error\", \"ignore\": [\"^e$\", \"^err$\"] }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Adopt a single error name (`error`) in every catch binding and rejection callback.","Use optional catch binding `catch {}` when the error object is unused.","Configure `name`/`ignore` once in .oxlintrc.json so legacy names do not flood CI when the preset is enabled."],"tags":["oxlint","lint","unicorn","naming","error-handling"],"backgroundTag":"catch-error-naming","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}