nonamedreturns icon indicating copy to clipboard operation
nonamedreturns copied to clipboard

[Good case] Handle errors in defer

Open kulti opened this issue 2 years ago • 4 comments

I hate named returns too :)

Well, one case are good and should be allowed by linter I suppose.

func f() (retErr error) {
	err := errors.New("foo")
	defer func() {
		if retErr == nil { // <-- analyse and replace returning error
			retErr = errors.New("bar")
		}
	}()
	return err
}

kulti avatar Jun 02 '22 12:06 kulti

will leave this issue open until dependabot has picked it up on the golangci-lint repo

firefart avatar Jun 12 '22 11:06 firefart

TODO once v1.0.4 is merged into golangci-lint (job runs sunday):

  • [ ] update option name in golangci-lint
  • [ ] update tests in golangci-lint

Reference: https://github.com/golangci/golangci-lint/pull/2915

firefart avatar Jun 25 '22 11:06 firefart

~Option is already added to golangci-lint (master branch)~

maratori avatar Jun 25 '22 11:06 maratori

golangci/golangci-lint#2944

maratori avatar Jun 26 '22 13:06 maratori