Skip to content

useErrorMessage

诊断类别:lint/suspicious/useErrorMessage

¥Diagnostic Category: lint/suspicious/useErrorMessage

自从:v1.8.0 来源:

¥Since: v1.8.0 Sources:

强制 onClick 至少伴随以下之一:

¥Enforce passing a message value when creating a built-in error.

此规则强制在创建内置 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

¥Invalid

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.

¥Valid

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

¥Related links