N818 error-suffix-on-exception-name false positives because it doesn't know if a given exception is an error
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 435
Description
I believe that this rule does more harm than good.
> you should use the suffix “Error” on your exception names (**if the exception actually is an error**).
- https://peps.python.org/pep-0008/#exception-names
The ratio of non-error exceptions to error exceptions varies depending on the specific task, but I'd assume it to be about 1:1. since Python encourages exceptions for control flow, which is kind of good in absence of Rust-like result types. For example:
- we may be calling some code to add funds to a user's account which may fail for a number of reasons, like: UserIsAnAdmin, UserSuspended, UserUnverified. Those are not errors, they are exceptions from the happy path of successfully adding funds.
- we may have a message processor which raises MessageIgnored for messages which i refuses to process based on its current functionality or configuration.
Meanwhile, there are already many important considerations when raising exceptions, like not reusing the same concrete exception type for more than one error. Having unreliable lint rules (which can be 50% incorrect) takes attention away from those very important considerations which cannot be linted for.
I suggest removing this rule and adding a more limited one which checks that an exception name doesn't end with `Exception` and suggests replacing the `Exception` suffix with `Error`.
At least, the message should be improved to, rather than saying `Exception name should be named with an Error suffix`, say `Exception name should be named with an Error suffix if it is an error, please ignore otherwise`.
Contributor guide
Assessment
This issue has not been assessed yet.