aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2022-06-01 14:40:41 -0400
committerRuss Cox <rsc@golang.org>2022-06-01 20:01:15 +0000
commit5579f240cbb7938362d82a9334c9f7a6a0d477b3 (patch)
tree375291757707881693c3b307b2598fc94598b0be
parentae62a0b8f23348d14a0270fafc2ee02ef5149a2e (diff)
downloadgo-x-review-5579f240cbb7938362d82a9334c9f7a6a0d477b3.tar.xz
git-codereview: print more about Gerrit API errors
For golang/go#50576. Change-Id: I3b67234098cbf9cd28bfa578c0b29744a4add2a3 Reviewed-on: https://go-review.googlesource.com/c/review/+/409914 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
-rw-r--r--git-codereview/api.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/git-codereview/api.go b/git-codereview/api.go
index 440489f..7a0da55 100644
--- a/git-codereview/api.go
+++ b/git-codereview/api.go
@@ -232,11 +232,15 @@ func (e *gerritError) Error() string {
// anti-xss line (]})' or some such) followed by JSON.
// If requestBody != nil, gerritAPI sets the Content-Type to application/json.
func gerritAPI(path string, requestBody []byte, target interface{}) (err error) {
+ var respBodyBytes []byte
defer func() {
if err != nil {
// os.Stderr, not stderr(), because the latter is not safe for
// use from multiple goroutines.
fmt.Fprintf(os.Stderr, "git-codereview: fetch %s: %v\n", path, err)
+ if len(respBodyBytes) > 0 {
+ fmt.Fprintf(os.Stderr, "Gerrit response:\n%s\n", respBodyBytes)
+ }
}
}()
@@ -281,6 +285,8 @@ func gerritAPI(path string, requestBody []byte, target interface{}) (err error)
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
+ respBodyBytes = body
+
if err != nil {
return fmt.Errorf("reading response body: %v", err)
}