-
Notifications
You must be signed in to change notification settings - Fork 357
Check errors and enable errcheck in lint config #2242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
I haven't gone through the changes in details, but I realize now that the list of errors to actually ignore is somewhat debatable in itself. I am leaning towards something like this: linters:
settings:
errcheck:
exclude-functions:
# Close
- (*github.com/fsnotify/fsnotify.Watcher).Close
- (*net.TCPConn).CloseWrite
- (*net.UnixConn).CloseWrite
- (*os.File).Close
- (io.Closer).Close
- (net.Conn).Close
- (net.Listener).Close
# Flush
- (*text/tabwriter.Writer).Flush
# Print
- fmt.Fprint
- fmt.Fprintf
- fmt.Fprintln
# Remove
- os.Remove
# Setenv
- os.SetenvNote that for switch c := c.(type) {
case *net.TCPConn:
c.CloseWrite()
case *net.UnixConn:
c.CloseWrite()
} |
|
Ok, happy to tune the exclusions. All the
I'm not convinced, because all of those act on an Re Anyway, it's all debatable as you say, so that's my contribution to the debate 😄
Nevermind, we need TCP mode for Windows. |
server.go
Outdated
| for s2.Scan() && s2.Text() != "" { | ||
| fmt.Fprintln(c, s2.Text()) | ||
| if _, err := fmt.Fprintln(c, s2.Text()); err != nil { | ||
| fmt.Printf("failed to forward query response from client %v: %s", id, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DId you mean to use echoerrf here, or was this intentional to avoid log spam?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this intentionally because at this point, we've just failed to send a message to connection c, which is what echoerrf would also try to do, so that's unlikely to succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echoerrf calls echoerr which writes the error back to the client but also logs the message. I think fmt.Printf won't be seen anywhere since the server runs in the background.
I could be wrong about this though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense. I've changed it to call log.Printf instead of fmt.Printf now. Does that work?
I think these are fair points, there are cases where handling these errors would be useful. Excluding a function directly means all usages are ignored by the linter, while leaving it enabled means that you have to specify These days I try to be accepting of the views of other contributors, so I am fine either way. I will tag @CatsDeservePets to see if he has anything to say about this PR. |
|
Thanks for tagging me, @joelim-work. To be honest, I think these rules are too harsh. This also makes contributing for less-involved users much harder and more annoying. They might not use a linter and write perfectly fine code, only to get linting errors later one. I think it should be up to the contributor (or the reviewer, by extension) to decide whether certain errors can be ignored or not. |
|
Ok, I believe I have addressed your comments now. We now have more blanket exclusions, and only a single remaining instance of the (previously admittedly somewhat noisy) |
So overall, it looks much better to me. Is this still in there for a reason |
The alternative is to blanket-exclude |
|
I'd say we can keep it as it is for now. |
I am also a bit concerned about blanket-excluding functions like this, this is why |
I was thinking about adding #nolint to make it more obvious what it does. But your suggestions is much better. I am in favour of this. |
Also, don't bother reporting os.Setenv() errors.
Done. |
joelim-work
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look fine now, thanks for working on them.
I will give my approval - @CatsDeservePets if you are happy with this as well then please merge the PR.
Following up to #2238, this un-disables the
errchecklinter in the golangci-lint config, and addresses all complaints by that linter; partly by handling the error, partly by explicitly ignoring it (e.g._ = f()), and partly through blanket-ignores in the config.I've additionally taken the opportunity to add some missing error handling to usages of
bufio.Scanner, where we were sometimes not calling.Err()to find out if an error happened. This was something I noticed myself.