git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 8/9] remote-curl: die directly with http error messages

From
Jeff King <peff@peff.net>
Date
Apr 5, 2013, 22:22 UTC
Message-ID
<20130405222215.GH22163@sigill.intra.peff.net>
In-Reply-To
<20130405221331.GA21209@sigill.intra.peff.net>

When we encounter an unknown http error (e.g., a 403), we hand the error code to http_error, which then prints it with error(). After that we die with the redundant message "HTTP request failed".

Instead, let's just drop http_error entirely, which does nothing but pass arguments to error(), and instead die directly with a useful message.

So before:
  $ git clone https://example.com/repo.git
  Cloning into 'repo'...
  error: unable to access 'https://example.com/repo.git': The requested URL returned error: 403 Forbidden
  fatal: HTTP request failed
and after:
  $ git clone https://example.com/repo.git
  Cloning into 'repo'...
  fatal: unable to access 'https://example.com/repo.git': The requested URL returned error: 403 Forbidden
Signed-off-by: Jeff King <peff@peff.net>
---
 remote-curl.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 9abe4b7..60eda63 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -216,8 +216,7 @@ static struct discovery* discover_refs(const char *service, int for_push)
 		die("Authentication failed for '%s'", url);
 	default:
 		show_http_message(&type, &buffer);
-		http_error(url);
-		die("HTTP request failed");
+		die("unable to access '%s': %s", url, curl_errorstr);
 	}
 
 	last= xcalloc(1, sizeof(*last_discovery));
-- 
1.8.2.rc0.33.gd915649
Previous: Jeff KingNext: Jeff King
Message 9 of 10 in “friendlier http error messages”
  1. 0/9 friendlier http error messagesJeff King, Apr 5, 2013
  2. 1/9 http: add HTTP_KEEP_ERROR optionJeff King, Apr 5, 2013
  3. 2/9 remote-curl: show server content on http errorsJeff King, Apr 5, 2013
  4. 3/9 remote-curl: let servers override http 404 adviceJeff King, Apr 5, 2013
  5. 4/9 remote-curl: always show friendlier 404 messageJeff King, Apr 5, 2013
  6. 5/9 remote-curl: consistently report repo url for http errorsJeff King, Apr 5, 2013
  7. 6/9 http: simplify http_error helper functionJeff King, Apr 5, 2013
  8. 7/9 http: re-word http error messageJeff King, Apr 5, 2013
  9. 8/9 remote-curl: die directly with http error messagesJeff King, Apr 5, 2013
  10. 9/9 http: drop http_error functionJeff King, Apr 5, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.