{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/17780","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/17780/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/17780/comments","events_url":"https://api.github.com/repos/golang/go/issues/17780/events","html_url":"https://github.com/golang/go/issues/17780","id":187171559,"number":17780,"title":"proposal: cmd/vet: can it detect \"defer resp.Body.Close()\"s that will panic?","user":{"login":"ahmetalpbalkan","id":159209,"avatar_url":"https://avatars.githubusercontent.com/u/159209?v=3","gravatar_id":"","url":"https://api.github.com/users/ahmetalpbalkan","html_url":"https://github.com/ahmetalpbalkan","followers_url":"https://api.github.com/users/ahmetalpbalkan/followers","following_url":"https://api.github.com/users/ahmetalpbalkan/following{/other_user}","gists_url":"https://api.github.com/users/ahmetalpbalkan/gists{/gist_id}","starred_url":"https://api.github.com/users/ahmetalpbalkan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahmetalpbalkan/subscriptions","organizations_url":"https://api.github.com/users/ahmetalpbalkan/orgs","repos_url":"https://api.github.com/users/ahmetalpbalkan/repos","events_url":"https://api.github.com/users/ahmetalpbalkan/events{/privacy}","received_events_url":"https://api.github.com/users/ahmetalpbalkan/received_events","type":"User","site_admin":false},"labels":[{"id":236419512,"url":"https://api.github.com/repos/golang/go/labels/Proposal","name":"Proposal","color":"ededed","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-11-03T19:47:24Z","updated_at":"2016-11-04T23:54:41Z","closed_at":null,"body":"This is a simple newbie mistake I saw in the Go code I wrote many years ago:\r\n\r\n```go\r\nresp, err := http.Get(...)\r\ndefer resp.Body.Close()\r\nif err != nil {\r\n    return err\r\n}\r\n// read resp.Body or something\r\n```\r\n\r\nThis will panic when `resp == nil` which is _iff_ `err != nil`. Can `go vet` have a heuristic for when `resp.Body.Close()` is invoked in a path where neither of the following are checked:\r\n\r\n- `resp != nil`\r\n- `err != nil`\r\n\r\nI don't know the specifics of how cmd/vet works but I was a little surprised when no static analysis tools caught this one so far (obviously points to lack of testing on my end as well, however I feel like static analysis could've found it earlier)."},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/258574870","html_url":"https://github.com/golang/go/issues/17780#issuecomment-258574870","issue_url":"https://api.github.com/repos/golang/go/issues/17780","id":258574870,"user":{"login":"bradfitz","id":2621,"avatar_url":"https://avatars.githubusercontent.com/u/2621?v=3","gravatar_id":"","url":"https://api.github.com/users/bradfitz","html_url":"https://github.com/bradfitz","followers_url":"https://api.github.com/users/bradfitz/followers","following_url":"https://api.github.com/users/bradfitz/following{/other_user}","gists_url":"https://api.github.com/users/bradfitz/gists{/gist_id}","starred_url":"https://api.github.com/users/bradfitz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bradfitz/subscriptions","organizations_url":"https://api.github.com/users/bradfitz/orgs","repos_url":"https://api.github.com/users/bradfitz/repos","events_url":"https://api.github.com/users/bradfitz/events{/privacy}","received_events_url":"https://api.github.com/users/bradfitz/received_events","type":"User","site_admin":false},"created_at":"2016-11-04T23:54:41Z","updated_at":"2016-11-04T23:54:41Z","body":"Yeah, that seems like a lot.\r\n"}}
{"actor":{"display_login":"bradfitz"}}