useErrorMessage
Diagnostic Category: lint/suspicious/useErrorMessage
Since: v1.8.0
Sources:
- Same as:
unicorn/error-message
Enforce passing a message value when creating a built-in error.
This rule enforces a message value to be passed in when creating an instance of a built-in Error
object,
which leads to more readable and debuggable code.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:12 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Provide an error message for the error.
> 1 │ throw Error();
│ ^^
2 │
ℹ Providing meaningful error messages leads to more readable and debuggable code.
code-block.js:1:12 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Error message should not be an empty string.
> 1 │ throw Error(”);
│ ^^^^
2 │
ℹ Providing meaningful error messages leads to more readable and debuggable code.
code-block.js:1:20 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Provide an error message for the error.
> 1 │ throw new TypeError();
│ ^^
2 │
ℹ Providing meaningful error messages leads to more readable and debuggable code.
code-block.js:1:33 lint/suspicious/useErrorMessage ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Provide an error message for the error.
> 1 │ const error = new AggregateError(errors);
│ ^^^^^^^^
2 │
ℹ Providing meaningful error messages leads to more readable and debuggable code.