{"record":{"id":"893f590d63366265","repo":"oxc-project/oxc","slug":"expected-error-to-be-handled","errorCode":null,"errorMessage":"Expected error to be handled.","messagePattern":"Expected error to be handled\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/node/handle_callback_err.rs","lineNumber":19,"sourceCode":"use std::borrow::Cow;\n\nuse lazy_regex::Regex;\nuse schemars::JsonSchema;\nuse serde::{Deserialize, de::Error as _};\n\nuse oxc_ast::{AstKind, ast::FormalParameters};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn handle_callback_err_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected error to be handled.\")\n        .with_help(\"Handle the error or rename the parameter if it's not an error.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Clone, JsonSchema)]\nenum ErrorPattern {\n    Plain(String),\n    Regex(Regex),\n}\n\nimpl Default for ErrorPattern {\n    fn default() -> Self {\n        Self::Plain(\"err\".to_string())\n    }\n}\n\nimpl ErrorPattern {\n    fn matches(&self, name: &str) -> bool {","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/node/handle_callback_err.rs#L1-L37","documentation":"Diagnostic from oxlint's port of ESLint's node/handle-callback-err rule. Node's callback convention passes an Error (or null) as the first argument; this rule reports functions whose first parameter matches the configured error name (default \"err\"; a string starting with `^` is parsed as a regex) but whose body never references it. Unread `err` means failures vanish silently and the success path runs on undefined data.","triggerScenarios":"A function or arrow function whose first FormalParameter is a binding identifier matching the configured pattern (default exactly `err`) with no usage of that identifier in the body: `function loadData(err, data) { doSomething(data); }`, `(err, rows) => render(rows)`. Configure e.g. `\"handle-callback-err\": [\"error\", \"^(err|error)$\"]` to match other names.","commonSituations":"Legacy Node callback-style code (fs, database drivers, Express middleware); a team naming the parameter `error` while the config stays at default `err` (false negatives) or vice versa (false positives on non-error params named err); refactors that deleted the error branch but kept the signature.","solutions":["Handle the error first: `if (err) { ... return; }` (or rethrow) before using the other arguments.","If the first parameter is not actually an error, rename it so it does not match the pattern.","Configure the pattern to your team's names: `[\"error\", \"^(err|error)$\"]` (leading ^ marks regex).","Suppress inline for a deliberate one-off, e.g. `// oxlint-disable-next-line handle-callback-err`."],"exampleFix":"// before\nfunction loadData(err, data) {\n  doSomething(data);\n}\n\n// after\nfunction loadData(err, data) {\n  if (err) throw err;\n  doSomething(data);\n}","handlingStrategy":"validation","validationCode":"// pattern matches your team's error-parameter names (leading ^ = regex)\n// .oxlintrc.json: \"node/handle-callback-err\": [\"error\", \"^(err|error)$\"]","typeGuard":"// the code shape the rule demands, applied preemptively\nfunction loadData(err: Error | null, data?: Buffer) {\n  if (err) throw err;\n  // safe success path\n}","tryCatchPattern":null,"preventionTips":["Always branch on the first callback argument before using the rest.","Standardize one error-parameter name repo-wide and encode it in the rule config.","For new code, prefer promise APIs and skip the callback pattern entirely."],"tags":["node","callbacks","error-handling","oxlint","lint","restriction"],"backgroundTag":"unhandled-callback-error","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}