-
Notifications
You must be signed in to change notification settings - Fork 1k
IND-2885 Linting #641
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
base: main
Are you sure you want to change the base?
IND-2885 Linting #641
Conversation
KaushikiAnand
commented
Apr 8, 2025
- I have added linting to go-tests.yml.
- The linting was done to ensure that the codebase is consistent and maintainable and helps in improving the code quality and reducing errors.
net_transport.go
Outdated
@@ -313,7 +314,9 @@ func (n *NetworkTransport) CloseStreams() { | |||
// entry. | |||
for k, e := range n.connPool { | |||
for _, conn := range e { | |||
conn.Release() | |||
if err := conn.Release(); err != nil { | |||
log.Print(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.
Suggestion: A more descriptive error message here would be helpful when tracing the error.
net_transport.go
Outdated
@@ -441,7 +442,9 @@ func (n *NetworkTransport) returnConn(conn *netConn) { | |||
if !n.IsShutdown() && len(conns) < n.maxPool { | |||
n.connPool[key] = append(conns, conn) | |||
} else { | |||
conn.Release() | |||
if err := conn.Release(); err != nil { | |||
log.Print(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.
Same as above.
net_transport.go
Outdated
var errors error | ||
defer func() { | ||
if err := conn.Release(); err != nil && errors == nil { | ||
errors = 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.
Question: Does setting it to errors server any purpose? I don't see it being used anywhere below.
@@ -635,7 +635,9 @@ func TestNetworkTransport_InstallSnapshot(t *testing.T) { | |||
|
|||
// Try to read the bytes | |||
buf := make([]byte, 10) | |||
rpc.Reader.Read(buf) | |||
if _, err := rpc.Reader.Read(buf); err != nil { | |||
t.Errorf("unable to read bytes: %v", 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.
Suggestion: Can we wrap the error instead of formatting it into the string i.e %v
-> %w
?
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.
There are a bunch of similar instances in raft.go
as well.
@@ -1859,7 +1859,7 @@ func TestRaft_Barrier(t *testing.T) { | |||
// Ensure all the logs are the same | |||
c.EnsureSame(t) | |||
if len(getMockFSM(c.fsms[0]).logs) != 100 { | |||
t.Fatalf(fmt.Sprintf("Bad log length: %d", len(getMockFSM(c.fsms[0]).logs))) | |||
t.Fatalf("%s", fmt.Sprintf("Bad log length: %d", len(getMockFSM(c.fsms[0]).logs))) |
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.
Question: Why not use t.Fatal(...)
instead?
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.
We need to be very careful about introducing behavior changes and swallowing important errors in production code for the sake of silencing lints. If we can't justify each change aside from lints I'm a -1 on this PR.
net_transport.go
Outdated
if err := conn.Release(); err != nil { | ||
return 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.
What's a circumstance where we're going to get an error here and want that to be the return value instead of the original error? (Similar for all these changes.)
if err := n.conn.conn.SetWriteDeadline(time.Now().Add(timeout)); err != nil { | ||
return nil, 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.
How does this change behavior in the caller? We're changing the error handling in many places in this PR. We're doing this for the sake of linting without much in the way of consideration for how it changes the expected behavior. "It silences linters" isn't a good enough reason to make this change without that consideration.
(This comment applies to a lot of these.)
raft.go
Outdated
if err := sink.Cancel(); err != nil { | ||
return fmt.Errorf("failed to cancel snapshot: %v", err) | ||
} | ||
return fmt.Errorf("failed to write snapshot: %v", 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.
Similar to the case I described in net_transport.go
, we're now swallowing the original error which is much more important for the caller to understand what's going on. This also applies anywhere else in this PR where we're doing this (there's a half dozen I can see).
@tgross
Thoughts? |
That's a reasonable approach. Another option would be to figure out which teardown functions we do need to care about and get the added error context wrapped in the original error we return. But that's certainly more work and needs more attention.
Why? It seems totally safe to add the extra checks for unit tests, right? |
The idea is fixing these linting checks in unit test files doesn't improve the actual library. I'm happy to include them too, no strong opinions here. We will keep them. |
This is a little all-or-nothing. Either the lint is useful, in which case you should apply it where it's safe to apply or it's not useful at all. I think it is useful, so applying it to test code in particular could be handy. Your change in e1a5e6a leaves a number of cases in the production code, however. |