{"record":{"id":"1ce34d10ebf14fa4","repo":"oxc-project/oxc","slug":"pass-the-error-message-to-super-instead-of-set","errorCode":null,"errorMessage":"Pass the error message to `super()` instead of setting `this.message`.","messagePattern":"Pass the error message to `super\\(\\)` instead of setting `this\\.message`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs","lineNumber":28,"sourceCode":"use 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\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces the only valid way of Error subclassing. It works with any super class that ends in Error.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Incorrectly defined custom errors can lead to unexpected behavior when","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs#L10-L46","documentation":"Lint diagnostic from unicorn/custom-error-definition: a custom error subclass sets this.message in its constructor body. That field is not enumerable and skips Error's normal initialization path; the message must be passed to super() for the error to behave like a native Error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs:28 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call super(message) in the constructor and delete the this.message assignment","Forward a default message when none is provided, e.g. super(message ?? 'MyError')"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}