Workhorse error handling in deferred functions
Problem
golangci
linter complains about lack of verification for errors in deferred functions.
Error return value of `content.Close` is not checked (errcheck)
During the refactoring this problem was addressed in several ways:
- Log an error in
defer
function
defer func() {
if err = content.Close(); err != nil {
fmt.Printf("Error closing file: %v", err)
}
}()
- Ignore the error
defer func() { _ = body.Close() }()
Currently, the codebase includes both options.
Proposal
- Discuss and define how should we handle this case
- Document the decision
- Unify codebase to follow the same approach
- Try to enforce it via golangci (if possible)