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 <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
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 @@
"io/ioutil"
"net/http"
"net/url"
+ "os"
"os/user"
"path/filepath"
"runtime"
@@ -230,7 +231,15 @@
// 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.