From 4e254029b1a55eb872fe30d833d67d446ba983c0 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Sun, 7 Apr 2024 23:30:57 +0200 Subject: [PATCH] Clarify HTTP cache put errors This might help diagnose problems like #739. --- server/http.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/server/http.go b/server/http.go index 6fe7bbba4..1134b826b 100644 --- a/server/http.go +++ b/server/http.go @@ -364,16 +364,18 @@ func (h *httpCache) CacheHandler(w http.ResponseWriter, r *http.Request) { // Ensure that the serialized ActionResult has non-zero length. ar, code, err := addWorkerMetadataHTTP(r.RemoteAddr, r.Header.Get("Content-Type"), data) if err != nil { - http.Error(w, err.Error(), code) - h.errorLogger.Printf("PUT %s: %s", path(kind, hash), err.Error()) + msg := "Failed to add worker metadata: " + err.Error() + http.Error(w, msg, code) + h.errorLogger.Printf("PUT %s: %s", path(kind, hash), msg) return } // Note: we do not currently verify that the blobs exist in the CAS. err = validate.ActionResult(ar) if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - h.errorLogger.Printf("PUT %s: %s", path(kind, hash), err.Error()) + msg := "Failed to marshal ActionResult: " + err.Error() + http.Error(w, msg, http.StatusBadRequest) + h.errorLogger.Printf("PUT %s: %s", path(kind, hash), msg) return } @@ -414,12 +416,15 @@ func (h *httpCache) CacheHandler(w http.ResponseWriter, r *http.Request) { err := h.cache.Put(r.Context(), kind, hash, contentLength, rdr) if err != nil { + var msg string if cerr, ok := err.(*cache.Error); ok { - http.Error(w, err.Error(), cerr.Code) + msg = cerr.Text + http.Error(w, msg, cerr.Code) } else { - http.Error(w, err.Error(), http.StatusInternalServerError) + msg = err.Error() + http.Error(w, msg, http.StatusInternalServerError) } - h.errorLogger.Printf("PUT %s: %s", path(kind, hash), err) + h.errorLogger.Printf("PUT %s: %s", path(kind, hash), msg) } else { h.logResponse(http.StatusOK, r) }