{"record":{"id":"8e9f1726d290188a","repo":"oxc-project/oxc","slug":"error-message-should-not-be-an-empty-string","errorCode":null,"errorMessage":"Error message should not be an empty string.","messagePattern":"Error message should not be an empty string\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/error_message.rs","lineNumber":21,"sourceCode":"    ast::{Argument, CallExpression, Expression, NewExpression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::IsGlobalReference;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::BUILT_IN_ERRORS};\n\nfn missing_message(ctor_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Pass a message to the {ctor_name:1} constructor.\"))\n        .with_help(\n            \"A descriptive message makes the error easier to debug when it is caught or logged.\",\n        )\n        .with_label(span)\n}\n\nfn empty_message(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Error message should not be an empty string.\")\n        .with_help(\"Provide a non-empty string that describes what went wrong.\")\n        .with_label(span)\n}\n\nfn not_string(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Error message should be a string.\")\n        .with_help(\n            \"The first argument to an error constructor should be a string describing the error.\",\n        )\n        .with_label(span)\n}\n\n#[derive(Default, Debug, Clone)]\npub struct ErrorMessage;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/error_message.rs#L3-L39","documentation":"Diagnostic from oxlint's `unicorn/error-message` rule. The message argument exists but is an empty string: either a `''`/`\"\"` string literal or an empty template literal (span of exactly two backtick characters). An empty message gives consumers of the error no information, so the rule asks for a non-empty string describing what went wrong.","triggerScenarios":"`throw new Error('')` or `` throw new Error(``) `` — the argument at the message position is a string literal with empty value. Only literals are checked; an empty-but-computed expression like `new Error(msg)` is not flagged.","commonSituations":"Placeholder errors written during development and never filled in; refactors that removed the message text but left the quotes; generated code that defaults messages to empty strings.","solutions":["Write a one-line description of the failure in the string.","If the message is built dynamically, guard it so it is never empty when thrown.","Add a lint step (`oxlint` with unicorn) to CI so placeholder errors are caught before merge."],"exampleFix":"// before\nthrow new Error('');\n// after\nthrow new Error('Failed to load configuration');","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never throw empty-string messages; write at least a short failure description.","If messages are built dynamically, default them to a meaningful constant instead of `''`.","Search the codebase for `Error('')` and `` Error(``) `` patterns during error-handling audits."],"tags":["oxlint","lint","unicorn","errors","debugging"],"backgroundTag":"error-constructor-message","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"}