Skip to content

Commit c0c0d38

Browse files
author
Ravi Tandon
committed
Fix errcheck in httpreplay
1 parent 1a7554c commit c0c0d38

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ debug.test
2323
docs/solutions/rhel74_image/ipxe.sh
2424
vendor/github.com/oracle/oci-go-sdk/target
2525
*.test
26+
oci/record/

httpreplay/common.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ package httpreplay
44

55
import (
66
"fmt"
7-
"gopkg.in/yaml.v2"
87
"log"
98
"net/http"
109
"os"
1110
"path/filepath"
11+
12+
"gopkg.in/yaml.v2"
1213
)
1314

1415
func initDebugStyle() {
@@ -26,7 +27,10 @@ var currentLogger *log.Logger
2627
// DebugLogf logs a formatted string to stderr. It should be considered temporary, and in a release version either removed or replaced with a passed-in logging interface.
2728
func debugLogf(format string, v ...interface{}) {
2829
if currentLogger != nil {
29-
currentLogger.Output(2, fmt.Sprintf(format, v...))
30+
err := currentLogger.Output(2, fmt.Sprintf(format, v...))
31+
if err != nil {
32+
log.Println("[WARN] Failed to write to current logger")
33+
}
3034
}
3135
// debug.PrintStack()
3236
}
@@ -66,8 +70,6 @@ func save(d interface{}, fn string) error {
6670
return err
6771
}
6872

69-
defer f.Close()
70-
7173
// Honor the YAML structure specification
7274
// http://www.yaml.org/spec/1.2/spec.html#id2760395
7375
_, err = f.Write([]byte("---\n"))
@@ -80,5 +82,9 @@ func save(d interface{}, fn string) error {
8082
return err
8183
}
8284

85+
err = f.Close()
86+
if err != nil {
87+
return err
88+
}
8389
return nil
8490
}

httpreplay/proxy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,10 @@ func (r *Proxy) Stop() error {
322322
// HandleRequest determine the calling roundTrip in different mode
323323
func (r *Proxy) HandleRequest(req *http.Request, realTransport http.RoundTripper) (*http.Response, error) {
324324
if r.mode == ByPassing {
325-
realTransport.RoundTrip(req)
325+
response, err := realTransport.RoundTrip(req)
326+
if err != nil {
327+
return response, err
328+
}
326329
}
327330

328331
_, resp, err := r.requestHandler(req, realTransport)

httpreplay/scenario.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package httpreplay
55
import (
66
"errors"
77
"fmt"
8-
"gopkg.in/yaml.v2"
98
"io/ioutil"
109
"net/http"
1110
"net/url"
@@ -14,6 +13,8 @@ import (
1413
"sort"
1514
"strings"
1615
"sync"
16+
17+
"gopkg.in/yaml.v2"
1718
)
1819

1920
// Scenario format versions
@@ -431,9 +432,6 @@ func (s *Scenario) Save() error {
431432
if err != nil {
432433
return err
433434
}
434-
defer func() {
435-
f.Close()
436-
}()
437435

438436
_, err = f.Write([]byte("---\n"))
439437
if err != nil {
@@ -455,6 +453,11 @@ func (s *Scenario) Save() error {
455453
//if err != nil {
456454
// return err
457455
//}
456+
457+
err = f.Close()
458+
if err != nil {
459+
return err
460+
}
458461
return nil
459462
}
460463

0 commit comments

Comments
 (0)