Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

registry,fleetctl: fix bugs regarding shadowed error variables - #1685

Merged
dongsupark merged 2 commits into
coreos:masterfrom
endocode:dongsu/fix-shadow-error-vars
Sep 21, 2016
Merged

registry,fleetctl: fix bugs regarding shadowed error variables#1685
dongsupark merged 2 commits into
coreos:masterfrom
endocode:dongsu/fix-shadow-error-vars

Conversation

@dongsupark

@dongsupark dongsupark commented Sep 19, 2016

Copy link
Copy Markdown
  • registry: make CreateUnit() explicitly return error

: When marshal() returns a non-nil error 'err', which shadows the pre-defined 'err', we should explicitly return the second error returned from marshal(). Otherwise it will always return nil. To fix other potential errors, let's just return err explicitly. This was discovered by running "go tool vet":

$ go tool vet --shadow ./registry
registry/job.go:316: declaration of "err" shadows declaration at registry/job.go:315
  • fleetctl: fix wrong error value from matchLocalFileAndUnit()

: In matchLocalFileAndUnit(), if os.Stat() returns nil and getUnitFromFile() returns non-nil error, then in the end matchLocalFileAndUnit() will return (false, nil). That's not the expected result. It should have returned the second error that came from getUnitFromFile(). To avoid further potential bugs, let's follow the idiomatic coding style: first check "err != nil", and fail-fast. This issue was discovered by running "go tool vet".

@tixxdz

tixxdz commented Sep 20, 2016

Copy link
Copy Markdown
Contributor

lgtm thanks @dongsupark , don't know why or if golang is supposed to warn about a local variable that shadows another local variable.

Dongsu Park added 2 commits September 21, 2016 10:44
When marshal() returns a non-nil error 'err', which shadows the
pre-defined 'err', we should explicitly return the second error returned
from marshal(). Otherwise it will always return nil.
To fix other potential bugs, let's just return err explicitly.

This was discovered by running go tool vet:

$ go tool vet --shadow ./registry
registry/job.go:316: declaration of "err" shadows declaration at registry/job.go:315
In matchLocalFileAndUnit(), if os.Stat() returns nil and
getUnitFromFile() returns non-nil error, then in the end
matchLocalFileAndUnit() will return (false, nil). That's not the
expected result. It should have returned the second error that came
from getUnitFromFile().

To avoid further potential bugs, let's follow the idiomatic coding
style: first check err != nil, and fail-fast.

This issue was discoverd by running go tools vet.
@dongsupark
dongsupark force-pushed the dongsu/fix-shadow-error-vars branch from 3da1508 to 3df18ae Compare September 21, 2016 08:45
@dongsupark
dongsupark merged commit b17e08b into coreos:master Sep 21, 2016
@dongsupark

Copy link
Copy Markdown
Author

@tixxdz Merged. Thanks for the review!

@dongsupark
dongsupark deleted the dongsu/fix-shadow-error-vars branch September 21, 2016 09:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants