4 ms·
> think most of this could be solved easily by either a compiler option or golint rule You mean like errcheck? https://github.com/kisielk/errcheck https://git
by NateDad 12y ago
> think most of this could be solved easily by either a compiler option or golint rule
You mean like errcheck? https://github.com/kisielk/errcheck https://github.com/kisielk/errcheck
I'm not sure if it can find spots where people intentionally throw away an error like in
val, _ := foo()
Usually people are more concerned with places where people accidentally fail to realize there's an error returned at all, like this:
func foo() error { ... }
foo() // errcheck finds this
However, it should be possible to find errors assigned to underscores, and thus detect that case.
- acdha 12y agoIdeally that'd move into the standard suite and you'd have to do something like compile with --repeat-the-mistakes-of-c to skip it. I've noticed most of the intention error punts in dense code where it looked like someone got tired of repeating checks and only checked the errors which happened while they were working. I'd bet a read-before-overwrite policy on _ would catch mostly infrequent environmental failures (i.e. the kind of stuff which only breaks when you're out of space, file handles, etc.).
- NateDad 12y agoAnyone who intentionally throws away errors because they "got tired" of checking errors, isn't someone I'd want on my team, and their code is not something I'd want to depend on, regardless of the language. Hopefully it would get caught in code review. But yes, it would be nice if go vet or go lint caught this syuff. Luckily, someone else wrote errcheck, and that's good enough.