Skip to content

Commit

Permalink
fix: gometalinter warnings for Artifactory pipeline
Browse files Browse the repository at this point in the history
gometalinter had several warnings about not respected
err return values from Close() calls
  • Loading branch information
andygrunwald committed Dec 2, 2017
1 parent 492a018 commit c1d2c28
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pipeline/artifactory/artifactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,12 @@ func runPipeOnBuild(ctx *context.Context, build config.Build) error {
})
}

if err := g.Wait(); err != nil {
return err
}

return nil
return g.Wait()
}

// doBuild runs the pipe action of the current build and the current target
// This is where the real action take place
func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target) error {
func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target) (err error) {
binary, err := getBinaryForUploadPerBuild(ctx, target)
if err != nil {
return err
Expand Down Expand Up @@ -163,7 +159,7 @@ func doBuild(ctx *context.Context, build config.Build, target buildtarget.Target
if err != nil {
return err
}
defer func() { _ = file.Close() }()
defer func() { err = file.Close() }()

artifact, resp, err := uploadBinaryToArtifactory(ctx, uploadTarget, artifactory.Username, secret, file)
if err != nil {
Expand Down Expand Up @@ -277,8 +273,8 @@ func newUploadRequest(target, username, secret string, reader io.Reader, size in
}

// executeHTTPRequest processes the http call with respect of context ctx
func executeHTTPRequest(ctx *context.Context, req *http.Request, v interface{}) (*http.Response, error) {
resp, err := http.DefaultClient.Do(req)
func executeHTTPRequest(ctx *context.Context, req *http.Request, v interface{}) (resp *http.Response, err error) {
resp, err = http.DefaultClient.Do(req)
if err != nil {
// If we got an error, and the context has been canceled,
// the context's error is probably more useful.
Expand All @@ -291,7 +287,9 @@ func executeHTTPRequest(ctx *context.Context, req *http.Request, v interface{})
return nil, err
}

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

err = checkResponse(resp)
if err != nil {
Expand Down Expand Up @@ -339,7 +337,10 @@ func checkResponse(r *http.Response) error {
errorResponse := &errorResponse{Response: r}
data, err := ioutil.ReadAll(r.Body)
if err == nil && data != nil {
json.Unmarshal(data, errorResponse)
err := json.Unmarshal(data, errorResponse)
if err != nil {
return err
}
}
return errorResponse
}

0 comments on commit c1d2c28

Please sign in to comment.