{"record":{"id":"07945e699e71a14b","repo":"oxc-project/oxc","slug":"missing-call-to-super-in-constructor","errorCode":null,"errorMessage":"Missing call to `super()` in constructor.","messagePattern":"Missing call to `super\\(\\)` in constructor\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs","lineNumber":20,"sourceCode":"    AstKind,\n    ast::{\n        AssignmentTarget, Class, ClassElement, Expression, MethodDefinitionKind,\n        PropertyDefinition, Statement,\n    },\n    match_member_expression,\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, ast_util, context::LintContext, rule::Rule};\n\nfn invalid_class_name_diagnostic(span: Span, expected: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Invalid class name, use `{expected}`.\")).with_label(span)\n}\n\nfn missing_super_call_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing call to `super()` in constructor.\").with_label(span)\n}\n\nfn invalid_name_property_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"The `name` property should be set to `{name}`.\")).with_label(span)\n}\n\nfn pass_message_to_super_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Pass the error message to `super()` instead of setting `this.message`.\")\n        .with_label(span)\n}\n\nfn invalid_export_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Exported error name should match error class\").with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct CustomErrorDefinition;\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs#L2-L38","documentation":"Diagnostic from oxlint's `unicorn/custom-error-definition` rule (pending category). A custom error class — one extending a statically-named `*Error` superclass — has a constructor with a body but no `super(...)` call among its statements. Without `super()`, the built-in `Error` machinery never initializes `message` and `stack`, so thrown instances print as empty errors and behave incorrectly under inspection. The diagnostic points at the constructor body.","triggerScenarios":"`class ApiError extends Error { constructor(message) { this.message = message; } }` — any constructor of a valid custom error class whose statement list contains no `super(...)` call. Constructors without bodies (overload signatures only) are ignored.","commonSituations":"Custom error classes written by copying plain-class patterns; refactors where `super(message)` was accidentally deleted; minified/transpiled code paths that dropped the super call.","solutions":["Add `super(message);` as the first statement of the constructor.","Remove any `this.message = message` assignment — `super()` already sets it.","Verify with `new ApiError('x').stack` that message and stack are now populated."],"exampleFix":"// before\nclass ApiError extends Error {\n  constructor(message) {\n    this.message = message;\n    this.name = 'ApiError';\n  }\n}\n// after\nclass ApiError extends Error {\n  constructor(message) {\n    super(message);\n    this.name = 'ApiError';\n  }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make `super(message)` the first statement of every custom error constructor.","Never set `this.message` manually — the super call owns it.","Smoke-test new error classes by logging `new MyError('x')` to confirm message and stack are populated."],"tags":["oxlint","lint","unicorn","errors","classes","constructor"],"backgroundTag":"custom-error-subclassing","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"}