From ae62a0b8f23348d14a0270fafc2ee02ef5149a2e Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 12 Apr 2022 16:16:53 -0400 Subject: git-codereview: print about all Gerrit API errors Trying to chase down a problem with slow builders. If this gets to be too chatty, we can limit it to builders. For golang/go#50576. Change-Id: I16c7818153d2444c897b4946ce7baebbd646ab23 Reviewed-on: https://go-review.googlesource.com/c/review/+/399116 Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Bryan Mills --- git-codereview/api.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/git-codereview/api.go b/git-codereview/api.go index 2adbcce..440489f 100644 --- a/git-codereview/api.go +++ b/git-codereview/api.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "net/http" "net/url" + "os" "os/user" "path/filepath" "runtime" @@ -230,7 +231,15 @@ func (e *gerritError) Error() string { // gerritAPI expects to get a 200 response with a body consisting of an // 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{}) error { +func gerritAPI(path string, requestBody []byte, target interface{}) (err error) { + 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) + } + }() + // Strictly speaking, we might be able to use unauthenticated // access, by removing the /a/ from the URL, but that assumes // that all the information we care about is publicly visible. -- cgit v1.3