cockroachdb / cockroachdb/cockroach
*: add a linter for errors that are just logged and swallowed
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Sometimes it is correct to log an error and not return it higher up in the call stack. But other times it is not correct, and the consequences of doing so can be severe. One example of this is covered in this post-mortem on bulk ingestion error handling: https://cockroachlabs.atlassian.net/wiki/x/EoB5DgE. The corresponding issue is https://github.com/cockroachdb/cockroach/issues/144650.
It can be pretty easy to forget to propagate an error simply because plumbing the error requires additional refactors. We already have a `https://github.com/cockroachdb/cockroach/issues/144650` linter that checks if an error is completely ignored: https://github.com/cockroachdb/cockroach/blob/c68c559859be738efead9971f5e11f62a8c69d06/pkg/testutils/lint/passes/returnerrcheck/returnerrcheck.go#L6-L9
We should enhance that or add a new linter that can also detect if an error is just logged and not returned. Sometimes that is correct behavior, so the linter should have an opt-out directive, like the existing approach of using `//nolint:returnerrcheck`.
Jira issue: CRDB-50600
Contributor guide
Assessment
This issue has not been assessed yet.