Skip to content

useErrorMessage

Diagnostic Category: lint/suspicious/useErrorMessage

Since: v1.8.0 Sources:

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.

throw Error();
code-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.

throw Error('');
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.

throw new TypeError();
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.

const error = new AggregateError(errors);
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.

throw Error('Unexpected property.');
throw new TypeError('Array expected.');
const error = new AggregateError(errors, 'Promises rejected.');