Skip to content

Commit

Permalink
Check errors (#431)
Browse files Browse the repository at this point in the history
* Added rakefile (original in github.com/Azure/autorest)

* Rakefile translated to golang

* Updated travis file

* Removed rakefile

* Included errcheck

* Fix metadata

* Removed panic

* Ignoring resp.body.Close() errors

* Discarding defer errors

* Fixed merged stuff

* Fix management errcheck

* Exclude errors rule in gas scanning

* Ignore checkerr issues involving Close()

* Get rid of gocheck, and add specific gas tests
  • Loading branch information
mcardosos authored and marstr committed Dec 13, 2016
1 parent 2e281a3 commit 2fb0ef4
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ install:

script:
- gas -skip=*/arm/*/models.go -skip=*/management/examples/*.go -skip=*vendor* -skip=*/Gododir/* ./...
- gas -exclude=G101 ./arm/... ./management/examples/...
- gas -exclude=G204 ./Gododir/...
- test -z "$(gofmt -s -l $(find ./arm/* -type d -print) | tee /dev/stderr)"
- test -z "$(gofmt -s -l -w management | tee /dev/stderr)"
- test -z "$(gofmt -s -l -w storage | tee /dev/stderr)"
Expand Down
14 changes: 10 additions & 4 deletions management/examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@ func main() {

fmt.Println("Create virtual machine")
role := vmutils.NewVMConfiguration(dnsName, vmSize)
vmutils.ConfigureDeploymentFromPlatformImage(
if err := vmutils.ConfigureDeploymentFromPlatformImage(
&role,
vmImage,
fmt.Sprintf("http://%s.blob.core.windows.net/%s/%s.vhd", storageAccount, dnsName, dnsName),
"")
vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword)
vmutils.ConfigureWithPublicSSH(&role)
""); err != nil {
panic(err)
}
if err := vmutils.ConfigureForLinux(&role, dnsName, userName, userPassword); err != nil {
panic(err)
}
if err := vmutils.ConfigureWithPublicSSH(&role); err != nil {
panic(err)
}

fmt.Println("Deploy")
operationID, err := virtualmachine.NewClient(client).
Expand Down
4 changes: 3 additions & 1 deletion management/vmutils/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func AddAzureDockerVMExtensionConfiguration(role *vm.Role, dockerPort int, versi
return fmt.Errorf(errParamNotSpecified, "role")
}

ConfigureWithExternalPort(role, "docker", dockerPort, dockerPort, vm.InputEndpointProtocolTCP)
if err := ConfigureWithExternalPort(role, "docker", dockerPort, dockerPort, vm.InputEndpointProtocolTCP); err != nil {
return err
}

publicConfiguration, err := createDockerPublicConfig(dockerPort)
if err != nil {
Expand Down
8 changes: 2 additions & 6 deletions storage/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,9 +537,7 @@ func (b BlobStorageClient) SetContainerPermissions(container string, containerPe
}

if resp != nil {
defer func() {
err = resp.body.Close()
}()
defer resp.body.Close()

if resp.statusCode != http.StatusOK {
return errors.New("Unable to set permissions")
Expand Down Expand Up @@ -575,9 +573,7 @@ func (b BlobStorageClient) GetContainerPermissions(container string, timeout int
// containerAccess. Blob, Container, empty
containerAccess := resp.headers.Get(http.CanonicalHeaderKey(ContainerAccessHeader))

defer func() {
err = resp.body.Close()
}()
defer resp.body.Close()

var out AccessPolicy
err = xmlUnmarshal(resp.body, &out.SignedIdentifiersList)
Expand Down
3 changes: 0 additions & 3 deletions storage/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ func (f FileServiceClient) ListDirsAndFiles(path string, params ListDirsAndFiles
if err != nil {
return out, err
}

defer resp.body.Close()
err = xmlUnmarshal(resp.body, &out)
return out, err
Expand Down Expand Up @@ -302,7 +301,6 @@ func (f FileServiceClient) ListShares(params ListSharesParameters) (ShareListRes
if err != nil {
return out, err
}

defer resp.body.Close()
err = xmlUnmarshal(resp.body, &out)
return out, err
Expand Down Expand Up @@ -400,7 +398,6 @@ func (f FileServiceClient) modifyRange(path string, bytes io.Reader, fileRange F
if err != nil {
return err
}

defer resp.body.Close()
return checkRespCode(resp.statusCode, []int{http.StatusCreated})
}
Expand Down
4 changes: 3 additions & 1 deletion storage/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func (c *TableServiceClient) QueryTables() ([]AzureTable, error) {
}

buf := new(bytes.Buffer)
buf.ReadFrom(resp.body)
if _, err := buf.ReadFrom(resp.body); err != nil {
return nil, err
}

var respArray queryTablesResponse
if err := json.Unmarshal(buf.Bytes(), &respArray); err != nil {
Expand Down
13 changes: 7 additions & 6 deletions storage/table_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ func (c *TableServiceClient) execTable(table AzureTable, entity TableEntity, spe

headers["Content-Length"] = fmt.Sprintf("%d", buf.Len())

var err error
var resp *odataResponse

resp, err = c.client.execTable(method, uri, headers, &buf)
resp, err := c.client.execTable(method, uri, headers, &buf)

if err != nil {
return 0, err
Expand Down Expand Up @@ -327,8 +324,12 @@ func deserializeEntity(retType reflect.Type, reader io.Reader) ([]TableEntity, e
}

// Reset PartitionKey and RowKey
tEntries[i].SetPartitionKey(pKey)
tEntries[i].SetRowKey(rKey)
if err := tEntries[i].SetPartitionKey(pKey); err != nil {
return nil, err
}
if err := tEntries[i].SetRowKey(rKey); err != nil {
return nil, err
}
}

return tEntries, nil
Expand Down

0 comments on commit 2fb0ef4

Please sign in to comment.