Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

chore: check all error returns in main code #3184

Merged
merged 4 commits into from
May 4, 2020

Conversation

mboersma
Copy link
Member

@mboersma mboersma commented May 2, 2020

Reason for Change:
Ignoring an error returned from a func can be a dangerous thing in go, so enabling the errcheck linter is good practice. This contains only the changes necessary to main code. See #3183 for changes to test code.

Issue Fixed:
Fixes #1032.

Requirements:

Notes:

@codecov
Copy link

codecov bot commented May 2, 2020

Codecov Report

Merging #3184 into master will decrease coverage by 0.08%.
The diff coverage is 50.60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3184      +/-   ##
==========================================
- Coverage   71.24%   71.15%   -0.09%     
==========================================
  Files         147      147              
  Lines       25753    25769      +16     
==========================================
- Hits        18348    18337      -11     
- Misses       6268     6286      +18     
- Partials     1137     1146       +9     
Impacted Files Coverage Δ
pkg/api/convertertoagentpoolonlyapi.go 89.93% <0.00%> (-0.59%) ⬇️
pkg/armhelpers/azureclient.go 35.02% <0.00%> (-0.93%) ⬇️
pkg/armhelpers/azurestack/azureclient.go 28.68% <0.00%> (-0.78%) ⬇️
pkg/armhelpers/azurestack/deploymentError.go 23.40% <0.00%> (ø)
pkg/operations/kubernetesupgrade/upgradecluster.go 81.17% <0.00%> (-1.53%) ⬇️
pkg/engine/transform/apimodel_merger.go 70.90% <11.11%> (-5.29%) ⬇️
cmd/deploy.go 62.10% <33.33%> (-0.52%) ⬇️
pkg/armhelpers/azurestack/converter.go 90.47% <50.00%> (-0.15%) ⬇️
pkg/armhelpers/converter.go 90.47% <50.00%> (-0.15%) ⬇️
cmd/addpool.go 18.81% <66.66%> (-0.11%) ⬇️
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b357dc4...64f07fa. Read the comment docs.

@@ -10,11 +10,10 @@ import (
// DeepCopy dst and src should be the same type in different API version
// dst should be pointer type
func DeepCopy(dst, src interface{}) error {
defer func() error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where were these deferred err responses going prior to this change? Does the caller to DeepCopy receive them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they were being ignored, because the only way to return a value from a defer in a func is a named result parameter. I'll try that change instead, because it would preserve the intent here and hopefully also placate the linter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this and the other DeepCopy...um...copy... as specified above.

@@ -211,7 +217,6 @@ func NewAzureClientWithClientSecretExternalTenant(env azure.Environment, subscri
if err != nil {
return nil, err
}
graphSpt.Refresh()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was returning a consistent error (once we started checking it). Need to investigate more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this and similar calls to log.Error(err) so as not to change existing control flow.

@mboersma mboersma force-pushed the errcheck-the-code branch from 15ae299 to 64f07fa Compare May 4, 2020 20:02
Copy link
Member

@jackfrancis jackfrancis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@acs-bot
Copy link

acs-bot commented May 4, 2020

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jackfrancis, mboersma

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [jackfrancis,mboersma]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@mboersma mboersma merged commit fce2924 into Azure:master May 4, 2020
@mboersma mboersma deleted the errcheck-the-code branch May 4, 2020 21:45
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.

Enable errcheck linter
3 participants