Skip to content

Commit c0799ad

Browse files
authored
DE-1365 Potential nil panic (#122)
1 parent 64ae3d7 commit c0799ad

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ jobs:
3333
- name: Install deps
3434
run: go mod download
3535

36-
# TODO(vtopc):
37-
# - name: nilaway
38-
# run: make nilaway
36+
- name: nilaway
37+
run: make nilaway
3938

4039
# TODO(vtopc):
4140
# - name: lint

.travis.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

core.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ var NbAttempt = 5
226226
// doRequest is called to execute the request. Authentification is set
227227
// with the public key and the secret key specified in MailjetClient.
228228
func (c *HTTPClient) doRequest(req *http.Request) (resp *http.Response, err error) {
229-
debugRequest(req) //DEBUG
229+
if req == nil {
230+
return nil, fmt.Errorf("req is nil")
231+
}
232+
233+
debugRequest(req) // DEBUG
230234
req.SetBasicAuth(c.apiKeyPublic, c.apiKeyPrivate)
231235
for attempt := 0; attempt < NbAttempt; attempt++ {
232236
if resp != nil {
@@ -237,7 +241,7 @@ func (c *HTTPClient) doRequest(req *http.Request) (resp *http.Response, err erro
237241
break
238242
}
239243
}
240-
defer debugResponse(resp) //DEBUG
244+
defer debugResponse(resp) // DEBUG
241245
if err != nil {
242246
return resp, fmt.Errorf("Error getting %s: %s", req.URL, err)
243247
}
@@ -247,6 +251,10 @@ func (c *HTTPClient) doRequest(req *http.Request) (resp *http.Response, err erro
247251

248252
// checkResponseError returns response error if the statuscode is < 200 or >= 400.
249253
func checkResponseError(resp *http.Response) error {
254+
if resp == nil {
255+
return fmt.Errorf("resp is nil")
256+
}
257+
250258
if resp.StatusCode < 200 || resp.StatusCode >= 400 {
251259
var mailjetErr RequestError
252260
mailjetErr.StatusCode = resp.StatusCode

http_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ func (c *HTTPClient) Call() (count, total int, err error) {
9292
c.mu.RLock()
9393
defer c.mu.RUnlock()
9494

95+
if c.request == nil {
96+
return 0, 0, fmt.Errorf("request is nil")
97+
}
98+
9599
defer c.reset()
96100
for key, value := range c.headers {
97101
c.request.Header.Add(key, value)

0 commit comments

Comments
 (0)