Skip to content
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

what about channel receives? #191

Open
seebs opened this issue Sep 28, 2020 · 3 comments
Open

what about channel receives? #191

seebs opened this issue Sep 28, 2020 · 3 comments

Comments

@seebs
Copy link

seebs commented Sep 28, 2020

While writing a similar tool, I ended up spending some time pondering under what circumstances Go allows a value to be generated-but-not-consumed. And there aren't all that many; it's mostly function call return values, since functions could have side-effects.

So could channel receives. So consider:

func foo(x chan error) {
  <-x
}

I would argue that this constitutes "failing to check an error".

@echlebek
Copy link
Collaborator

I like the idea. I'm a bit fuzzy on some of the details.

Ignoring for a moment that channel receives are a bit different to analyze than function calls, I'm wondering about the extent of channel receive scenarios that would be considered unchecked. Would we consider any channel receive that gets an error, and discards it, an errcheck error?

In addition to your example, what about these?

x := make(chan error)
for range x {
}
x := make(chan error)
select {
  case <-x:
  case <-y:
}
x := make(chan error)
y := make(chan error)
y <- <-x

3 is kind of funny and I just included it as a pseudo test case. We aren't assigning the error to anything, but we are using it. (Of course, intuitively, this would be "not an errcheck error")

@seebs
Copy link
Author

seebs commented Sep 29, 2020

So, in the tool I wrote, I ignore questions like "channel receives" and "function calls", and just look at the type of the expression of an ExprStmt. But it occurs to me that range and select calls are also arguably examples, and I should think about that more.

I would consider any form of "use" (sending to a channel, passing to a function, etc.) to count as a valid "use". On the other hand, it seems to me that I wasn't thinking about the range and select cases. There's nothing corresponding for the function call case I was originally thinking about, so I didn't really get into that space.

So I think I would consider the first two of those to be examples of "this is an error that isn't being checked".

@kisielk
Copy link
Owner

kisielk commented Mar 9, 2023

Apparently github.com/molecula/noticeme may implement this. Can look there for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants