Skip to content

Commit

Permalink
Be robust to lack of internet connection when reporting a crash (#558)
Browse files Browse the repository at this point in the history
Fix the error handling: if err != nil, then 'res' might be nil,
causing a nil-pointer error in the error message formatting. Properly
handle err != nil and wrong HTTP status code in two separate steps.

Bug: b/169547718
Test: manual (force-crash replay while having internet disconnected)
  • Loading branch information
hevrard authored Nov 17, 2020
1 parent db78b28 commit 9ed9c9b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/app/crash/reporting/reporting.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ func (r Reporter) sendReport(body io.Reader, contentType, endpoint string) (stri
if err == nil {
defer res.Body.Close()
}
if err != nil || res.StatusCode != http.StatusOK {
return "", fmt.Errorf("Failed to upload report request: %v (%v)", err, res.StatusCode)
if err != nil {
return "", fmt.Errorf("Failed to upload report request: %v", err)
}
if res.StatusCode != http.StatusOK {
return "", fmt.Errorf("Failed to upload report request: got HTTP status code %v", res.StatusCode)
}

buf := new(bytes.Buffer)
Expand Down

0 comments on commit 9ed9c9b

Please sign in to comment.