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

Commit b17e08b

Browse files
author
Dongsu Park
authored
Merge pull request #1685 from endocode/dongsu/fix-shadow-error-vars
registry,fleetctl: fix bugs regarding shadowed error variables
2 parents b2e537c + 3df18ae commit b17e08b

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

fleetctl/fleetctl.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -833,18 +833,19 @@ func lazyCreateUnits(cCmd *cobra.Command, args []string) error {
833833
// Returns true if the contents of the file matches the unit one, false
834834
// otherwise; and any error encountered.
835835
func matchLocalFileAndUnit(file string, su *schema.Unit) (bool, error) {
836-
result := false
837836
a := schema.MapSchemaUnitOptionsToUnitFile(su.Options)
838837

839838
_, err := os.Stat(file)
840-
if err == nil {
841-
b, err := getUnitFromFile(file)
842-
if err == nil {
843-
result = unit.MatchUnitFiles(a, b)
844-
}
839+
if err != nil {
840+
return false, err
841+
}
842+
843+
b, err := getUnitFromFile(file)
844+
if err != nil {
845+
return false, err
845846
}
846847

847-
return result, err
848+
return unit.MatchUnitFiles(a, b), nil
848849
}
849850

850851
// isLocalUnitDifferent compares a Unit on the file system with a one

registry/job.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (r *EtcdRegistry) DestroyUnit(name string) error {
312312
}
313313

314314
// CreateUnit attempts to store a Unit and its associated unit file in the registry
315-
func (r *EtcdRegistry) CreateUnit(u *job.Unit) (err error) {
315+
func (r *EtcdRegistry) CreateUnit(u *job.Unit) error {
316316
if err := r.storeOrGetUnitFile(u.Unit); err != nil {
317317
return err
318318
}
@@ -323,7 +323,7 @@ func (r *EtcdRegistry) CreateUnit(u *job.Unit) (err error) {
323323
}
324324
val, err := marshal(jm)
325325
if err != nil {
326-
return
326+
return err
327327
}
328328

329329
opts := &etcd.SetOptions{
@@ -335,7 +335,7 @@ func (r *EtcdRegistry) CreateUnit(u *job.Unit) (err error) {
335335
key := r.prefixed(jobPrefix, u.Name, "object")
336336
_, err = r.kAPI.Set(context.Background(), key, val, opts)
337337
if err != nil {
338-
return
338+
return err
339339
}
340340

341341
return r.SetUnitTargetState(u.Name, u.TargetState)

0 commit comments

Comments
 (0)