{"record":{"id":"598ea44e5d0d5a34","repo":"oxc-project/oxc","slug":"missing-throw","errorCode":null,"errorMessage":"Missing throw","messagePattern":"Missing throw","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/oxc/missing_throw.rs","lineNumber":9,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn missing_throw_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing throw\")\n        .with_help(\"The `throw` keyword seems to be missing in front of this 'new' expression\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct MissingThrow;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Checks whether the `throw` keyword is missing in front of a `new` expression.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `throw` keyword is required in front of a `new` expression to throw an error. Omitting it is usually a mistake.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/oxc/missing_throw.rs#L1-L27","documentation":"Oxlint rule `oxc/missing-throw` flags a `new Error(...)` expression used as a bare statement: as an ExpressionStatement or inside a block-bodied arrow function. The error object is constructed and immediately discarded — nothing is thrown or returned — so the surrounding function silently continues on what was meant to be a failure path. Only the exact callee `Error` is checked, and an autofix inserts `throw ` before the expression.","triggerScenarios":"`function foo() { new Error('boom') }`; `const fail = () => { new Error('nope') }`. Not flagged: `throw new Error()`, the expression-bodied `() => new Error()` (it returns the error), or `[new Error()]`.","commonSituations":"Deleting `throw` while editing; converting an arrow function from expression body to block body and dropping the throw; error-handling code written but never wired up, so failures pass silently.","solutions":["Add `throw`: `throw new Error('boom')` (autofix inserts it)","If the arrow should produce the error rather than throw it, return it instead","Search the codebase for other bare `new Error(` statements — oxlint lists every occurrence"],"exampleFix":"// before\nconst fail = () => { new Error('nope'); };\n\n// after\nconst fail = () => { throw new Error('nope'); };","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — correctness rule with autofix\n{\n  \"rules\": { \"oxc/missing-throw\": \"error\" }\n}\n// CLI (inserts `throw`): npx oxlint --fix src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Every `new Error(` you type should be preceded by `throw`, `return`, or an assignment","Write tests asserting that failure paths actually throw (`expect(fn).toThrow()`)","When converting arrows from expression to block body, re-check error paths"],"tags":["oxlint","oxc","error-handling","logic-bug","javascript","static-analysis"],"backgroundTag":"missing-throw-statement","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"}