{"action":"closed","issue":{"url":"https://api.github.com/repos/golang/go/issues/18425","repository_url":"https://api.github.com/repos/golang/go","labels_url":"https://api.github.com/repos/golang/go/issues/18425/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/18425/comments","events_url":"https://api.github.com/repos/golang/go/issues/18425/events","html_url":"https://github.com/golang/go/issues/18425","id":197484532,"number":18425,"title":"[Feature Request] Shorter error catching","user":{"login":"graarh","id":1476855,"avatar_url":"https://avatars.githubusercontent.com/u/1476855?v=3","gravatar_id":"","url":"https://api.github.com/users/graarh","html_url":"https://github.com/graarh","followers_url":"https://api.github.com/users/graarh/followers","following_url":"https://api.github.com/users/graarh/following{/other_user}","gists_url":"https://api.github.com/users/graarh/gists{/gist_id}","starred_url":"https://api.github.com/users/graarh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graarh/subscriptions","organizations_url":"https://api.github.com/users/graarh/orgs","repos_url":"https://api.github.com/users/graarh/repos","events_url":"https://api.github.com/users/graarh/events{/privacy}","received_events_url":"https://api.github.com/users/graarh/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-12-25T02:18:26Z","updated_at":"2016-12-25T17:12:42Z","closed_at":"2016-12-25T17:12:42Z","body":"Lets look at the common function\r\n\r\n```go\r\nfunc MyFunc() (*SomeStruct, int, error) {\r\n    data, err := callSomething()\r\n    if err != nil {\r\n        return nil, 0, err\r\n    }\r\n    return data, callSomethingOther(), nil\r\n}\r\n```\r\n\r\nthe \r\n\r\n```go\r\nif err != nil {\r\n   return <default type value>, <default type value>, err\r\n}\r\n```\r\n\r\nis the most common error checking code. But it can be removed by adding syntax construction like\r\n\r\n```go\r\nfunc MyFunc() (*SomeStruct, int, error) {\r\n    data, <err> := callSomething()\r\n    return data, callSomethingOther(), nil\r\n}\r\n```\r\n\r\nthat means if the err is not nil, exit from the function and return default type values except error value. It should not compile if more than one error type returned. \r\n\r\nIt is pretty clean for reading, and removes a lot of code lines with identical error checking."}}
{"actor":{"display_login":"graarh"}}