cmd/vet: vet should recommend "os.IsNotExist(err)" over "err == os.ErrNotExist" #19267
Comments
Is this mistake really common enough that it deserves a vet check? |
In my own corpus (most public Go packages), there are 229 matches for Among the 229 results are matches in camlistore, rkt and docker. |
@ianlancetaylor, I seldom write file io programs. I think it is so natural that use "err == os.ErrNotExist" to check if a file exists or not when I used the io.Open function the first time. But I was wrong. |
But in Camlistore we have interfaces documenting that os.ErrNotExist is the contract between our own interfaces and our own implementations. A sample:
I think this vet check would be noisier than it would be helpful. |
I don't think this merits a vet check. Remember it must satisfy the criteria specified in the readme of correctness, frequency, and precision. It fails for correctness and is marginal for frequency and precision. |
It looks the ErrNotExist variable in os package shouldn't be exported at all.
The text was updated successfully, but these errors were encountered: