Skip to content

Commit

Permalink
Merge pull request #2186 from mtrmac/quote-response-body
Browse files Browse the repository at this point in the history
Quote the response body in an error message
  • Loading branch information
vrothberg authored Nov 14, 2023
2 parents 1af240e + d55a5eb commit 96eab26
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docker/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func registryHTTPResponseToError(res *http.Response) error {
response = response[:50] + "..."
}
// %.0w makes e visible to error.Unwrap() without including any text
err = fmt.Errorf("StatusCode: %d, %s%.0w", e.StatusCode, response, e)
err = fmt.Errorf("StatusCode: %d, %q%.0w", e.StatusCode, response, e)
case errcode.Error:
// e.Error() is fmt.Sprintf("%s: %s", e.Code.Error(), e.Message, which is usually
// rather redundant. So reword it without using e.Code.Error() if e.Message is the default.
Expand Down
4 changes: 2 additions & 2 deletions docker/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRegistryHTTPResponseToError(t *testing.T) {
"Header1: Value1\r\n" +
"\r\n" +
"<html><body>JSON? What JSON?</body></html>\r\n",
errorString: "StatusCode: 400, <html><body>JSON? What JSON?</body></html>\r\n",
errorString: `StatusCode: 400, "<html><body>JSON? What JSON?</body></html>\r\n"`,
errorType: nil,
unwrappedErrorPtr: &unwrappedUnexpectedHTTPResponseError,
},
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestRegistryHTTPResponseToError(t *testing.T) {
"X-Docker-Size: -1\r\n" +
"\r\n" +
"Not found\r\n",
errorString: "StatusCode: 404, Not found\r",
errorString: `StatusCode: 404, "Not found\r"`,
errorType: nil,
unwrappedErrorPtr: &unwrappedUnexpectedHTTPResponseError,
fn: func(t *testing.T, err error) {
Expand Down

0 comments on commit 96eab26

Please sign in to comment.