Skip to content

Commit 8fb1073

Browse files
Ineffassign fixes
The following are potential juju issues spotted by ineffassign linter. We should really consider cherry-picking these as they're potentially real world fixes. Before doing that we should really also check if every one is valid.
1 parent 599ee1b commit 8fb1073

File tree

55 files changed

+123
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+123
-46
lines changed

apiserver/facades/agent/storageprovisioner/shim.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ func NewFacadeV3(st *state.State, resources facade.Resources, authorizer facade.
3333
registry, err := stateenvirons.NewStorageProviderRegistryForModel(
3434
model,
3535
stateenvirons.GetNewEnvironFunc(environs.New),
36-
stateenvirons.GetNewCAASBrokerFunc(caas.New))
36+
stateenvirons.GetNewCAASBrokerFunc(caas.New),
37+
)
38+
if err != nil {
39+
return nil, errors.Trace(err)
40+
}
3741
pm := poolmanager.New(state.NewStateSettings(st), registry)
3842

3943
backend, storageBackend, err := NewStateBackends(st)

apiserver/facades/agent/uniter/uniter.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,6 +1219,9 @@ func (u *UniterAPI) RelationsStatus(args params.Entities) (params.RelationUnitSt
12191219
return nil, errors.Trace(err)
12201220
}
12211221
relations, err := app.Relations()
1222+
if err != nil {
1223+
return nil, errors.Trace(err)
1224+
}
12221225
for _, rel := range relations {
12231226
rus, err := oneRelationUnitStatus(rel, unit)
12241227
if err != nil {

apiserver/facades/client/application/charmstore.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func AddCharmWithAuthorizationAndRepo(st State, args params.AddCharmWithAuthoriz
117117

118118
// Get the repo from the constructor
119119
repo, err := repoFn()
120+
if err != nil {
121+
return errors.Trace(err)
122+
}
120123

121124
// Get the charm and its information from the store.
122125
downloadedCharm, err := repo.Get(charmURL)

apiserver/facades/client/applicationoffers/base.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (api *BaseAPI) applicationOffersFromModel(
118118

119119
// If requireAdmin is true, the user must be a controller superuser
120120
// or model admin to proceed.
121-
isAdmin := false
121+
var isAdmin bool
122122
err = api.checkAdmin(backend)
123123
if err != nil && err != common.ErrPerm {
124124
return nil, errors.Trace(err)

apiserver/facades/client/client/status.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,9 @@ func (c *Client) StatusHistory(request params.StatusHistoryRequests) params.Stat
133133
continue
134134
}
135135

136-
var (
137-
err error
138-
hist []params.DetailedStatus
139-
)
136+
var err error
137+
var hist []params.DetailedStatus
140138
kind := status.HistoryKind(request.Kind)
141-
err = errors.NotValidf("%q requires a unit, got %T", kind, request.Tag)
142139
switch kind {
143140
case status.KindUnit, status.KindWorkload, status.KindUnitAgent:
144141
var u names.UnitTag
@@ -662,6 +659,9 @@ func fetchAllApplicationsAndUnits(
662659
unitMap := make(map[string]map[string]*state.Unit)
663660
latestCharms := make(map[charm.URL]*state.Charm)
664661
applications, err := st.AllApplications()
662+
if err != nil {
663+
return applicationStatusInfo{}, err
664+
}
665665
units, err := model.AllUnits()
666666
if err != nil {
667667
return applicationStatusInfo{}, err

apiserver/facades/client/keymanager/keymanager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ func runSSHKeyImport(keyIds []string) map[string][]importedSSHKey {
262262
output, err := RunSSHImportId(keyId)
263263
if err != nil {
264264
keyInfo = append(keyInfo, importedSSHKey{err: err})
265+
importResults[keyId] = keyInfo
265266
continue
266267
}
267268
lines := strings.Split(output, "\n")

apiserver/facades/client/machinemanager/instance_information.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func instanceTypes(mm *MachineManagerAPI,
4242
}
4343

4444
env, err := getEnviron(backend, environs.New)
45+
if err != nil {
46+
return params.InstanceTypesResults{}, errors.Trace(err)
47+
}
4548
result := make([]params.InstanceTypesResult, len(cons.Constraints))
4649
// TODO(perrito666) Cache the results to avoid excessive querying of the cloud.
4750
for i, c := range cons.Constraints {

apiserver/gui.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,9 @@ func (h *guiArchiveHandler) handlePost(w http.ResponseWriter, req *http.Request)
590590

591591
// Read and validate the archive data.
592592
data, hash, err := readAndHash(req.Body)
593+
if err != nil {
594+
return errors.Trace(err)
595+
}
593596
size := int64(len(data))
594597
if size != req.ContentLength {
595598
return errors.BadRequestf("archive does not match provided content length")

apiserver/stateauthenticator/modeluser.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ func (u *modelUserEntity) UpdateLastLogin() error {
166166
return errors.NotValidf("%s as model user", u.modelUser.Object.Kind())
167167
}
168168

169-
model, err := u.st.Model()
169+
var model *state.Model
170+
model, err = u.st.Model()
170171
if err != nil {
171172
return errors.Trace(err)
172173
}
@@ -177,7 +178,7 @@ func (u *modelUserEntity) UpdateLastLogin() error {
177178
if u.user != nil {
178179
err1 := u.user.UpdateLastLogin()
179180
if err == nil {
180-
return err1
181+
return errors.Trace(err1)
181182
}
182183
}
183184
if err != nil {

caas/kubernetes/provider/k8s.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,9 @@ func (k *kubernetesClient) Operator(appName string) (*caas.Operator, error) {
22852285
terminated := opPod.DeletionTimestamp != nil
22862286
now := time.Now()
22872287
statusMessage, opStatus, since, err := k.getPODStatus(opPod, now)
2288+
if err != nil {
2289+
return nil, errors.Trace(err)
2290+
}
22882291
return &caas.Operator{
22892292
Id: string(opPod.UID),
22902293
Dying: terminated,

0 commit comments

Comments
 (0)