{"record":{"id":"9a6d92bce3709a4e","repo":"oxc-project/oxc","slug":"exported-error-name-should-match-error-class","errorCode":null,"errorMessage":"Exported error name should match error class","messagePattern":"Exported error name should match error class","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs","lineNumber":33,"sourceCode":"fn 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\n    /// catching and identifying errors. Missing `super()` calls, wrong `name`\n    /// property values, or non-standard class names make error handling unreliable.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs#L15-L51","documentation":"Lint diagnostic from unicorn/custom-error-definition (invalid_export_diagnostic): a module exports an error class under a name that does not match the class name (e.g. export { FooError as BarError } or export default). Mismatched names make stack traces and instanceof checks harder to follow.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs:33 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Export the class under its own name (export class FooError / export { FooError })","Rename the class itself to the intended exported name"],"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-14T00:17:10.932Z"}