Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote the response body in an error message #2186

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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