prefer-correct-error-name

Group
Style
Path
lint/style/prefer-correct-error-name
Default
Off, opt in
Origin
Falcon
Rule
337 of 512

Require configured error parameter names in catches and SDK error callbacks.

Set allowed-names to a nonempty string array to enable the rule. Optional ignored-names exempts names. Stack-trace parameters are not checked. Callback checks require a resolved dart:async Future or Stream receiver; unrelated APIs, tear-offs and dynamic receivers are excluded.

Invalid

example.dartdart
import 'dart:async';
void check(Future<int> future, Stream<int> stream) {
  try {} catch (err) {}
  future.then((value) => value, onError: (e) {});
  future.catchError((failure) => 0);
  stream.listen((value) {}, onError: (err, stack) {});
  stream.handleError((err) {});
}
This error parameter does not match the configured names; rename it to one of: `error`, `exception`.
2void check(Future<int> future, Stream<int> stream) {
3 try {} catch (err) {}
This error parameter does not match the configured names; rename it to one of: `error`, `exception`.
3 try {} catch (err) {}
4 future.then((value) => value, onError: (e) {});
This error parameter does not match the configured names; rename it to one of: `error`, `exception`.
4 future.then((value) => value, onError: (e) {});
5 future.catchError((failure) => 0);
This error parameter does not match the configured names; rename it to one of: `error`, `exception`.
5 future.catchError((failure) => 0);
6 stream.listen((value) {}, onError: (err, stack) {});
This error parameter does not match the configured names; rename it to one of: `error`, `exception`.
6 stream.listen((value) {}, onError: (err, stack) {});
7 stream.handleError((err) {});

Valid

example.dartdart
import 'dart:async';
void check(Future<int> future, Stream<int> stream, dynamic unknown) {
  try {} catch (error, stackTrace) {}
  try {} catch (exception) {}
  try {} catch (ignored) {}
  try {} catch (_) {}
  try {} catch (__) {}
  future.catchError((_) => 0);
  future.catchError((error) => 0);
  stream.handleError((exception) {});
  unknown.catchError((e) {});
  future.then((value) => value);
}

Configure prefer-correct-error-name

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "prefer-correct-error-name": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/prefer-correct-error-name: <reason>