{"thread":{"id":"1951","subject":"[PATCH 3/3] Return CURL error message when object transfer fails","startedAt":"2005-09-26T17:52:11Z","lastAt":"2005-09-27T16:07:41Z","messageCount":6,"participants":["Nick Hengeveld","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"9308","messageId":"20050926175211.GD9410@reactrix.com","threadId":"1951","inReplyTo":null,"subject":"[PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-09-26T17:52:11Z","receivedAt":"2005-09-26T17:52:11Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"\nReturn CURL error message when object transfer fails\n\nSigned-off-by: Nick Hengeveld <nickh@reactrix.com>\n\n\n---\n\nIt might be better to extend this to all places that curl_easy_perform\nis called, rather than just in fetch_object.\n\n http-fetch.c |    4 +++-\n 1 files changed, 3 insertions(+), 1 deletions(-)\n\n330da7634e6a707779dcc8648841f501d2a47568\ndiff --git a/http-fetch.c b/http-fetch.c\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -19,6 +19,7 @@\n static CURL *curl;\n static struct curl_slist *no_pragma_header;\n static struct curl_slist *no_range_header;\n+static char curl_errorstr[CURL_ERROR_SIZE];\n \n static char *initial_base;\n \n@@ -389,6 +390,7 @@ int fetch_object(struct alt_base *repo, \n \tcurl_easy_setopt(curl, CURLOPT_FILE, NULL);\n \tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \n \turl = xmalloc(strlen(repo->base) + 50);\n \tstrcpy(url, repo->base);\n@@ -448,7 +450,7 @@ int fetch_object(struct alt_base *repo, \n \tcurl_result = curl_easy_perform(curl);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_range_header);\n \tif (curl_result != 0) {\n-\t\treturn -1;\n+\t\treturn error(curl_errorstr);\n \t}\n \n \tfchmod(local, 0444);\n"},{"id":"9329","messageId":"7v4q87ed73.fsf@assigned-by-dhcp.cox.net","threadId":"1951","inReplyTo":"20050926175211.GD9410@reactrix.com","subject":"Re: [PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-26T21:22:56Z","receivedAt":"2005-09-26T21:22:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nick Hengeveld <nickh@reactrix.com> writes:\n\n> It might be better to extend this to all places that curl_easy_perform\n> is called, rather than just in fetch_object.\n\nSounds like a good idea.  Also if you happen to know if this\noption is not available in older versions of the library, it\nmight not hurt to guard it with \"#if LIBCURL_VERSION_NUM\" like\nwe do with other options.\n"},{"id":"9349","messageId":"20050927001241.GB15615@reactrix.com","threadId":"1951","inReplyTo":"7v4q87ed73.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-09-27T00:12:41Z","receivedAt":"2005-09-27T00:12:41Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"On Mon, Sep 26, 2005 at 02:22:56PM -0700, Junio C Hamano wrote:\n\n> Sounds like a good idea.  Also if you happen to know if this\n> option is not available in older versions of the library, it\n> might not hurt to guard it with \"#if LIBCURL_VERSION_NUM\" like\n> we do with other options.\n\nI don't see any indication that CURLOPT_ERRORBUFFER is a new feature.\nThe curl_easy_strerror() function is new as of 7.12.0 which is why\nI elected to use the CURLOPT_ERRORBUFFER option instead.\n\n-- \nFor a successful technology, reality must take precedence over public\nrelations, for nature cannot be fooled.\n"},{"id":"9364","messageId":"7v3bnr3vo5.fsf@assigned-by-dhcp.cox.net","threadId":"1951","inReplyTo":"20050927001241.GB15615@reactrix.com","subject":"Re: [PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-27T05:51:38Z","receivedAt":"2005-09-27T05:51:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nick Hengeveld <nickh@reactrix.com> writes:\n\n> I don't see any indication that CURLOPT_ERRORBUFFER is a new feature.\n> The curl_easy_strerror() function is new as of 7.12.0 which is why\n> I elected to use the CURLOPT_ERRORBUFFER option instead.\n\nIf that is the case, I'll take your patch verbatim.  Thanks.\n\nI just needed to get the feel that you did things that way,\nknowing what to and what not to worry about; I am no cURL\nexpert.\n"},{"id":"9366","messageId":"7vpsqv2g3p.fsf@assigned-by-dhcp.cox.net","threadId":"1951","inReplyTo":"7v3bnr3vo5.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-09-27T06:13:14Z","receivedAt":"2005-09-27T06:13:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <junkio@cox.net> writes:\n\n> If that is the case, I'll take your patch verbatim.  Thanks.\n\nOops.  I spoke too fast.  That \"sounds like a good idea\" of mine\nwas a response to your:\n\n> It might be better to extend this to all places that curl_easy_perform\n> is called, rather than just in fetch_object.\n\n... so the patch still needed some fixups.  It had minor\ndependencies on the previous patches in the series as well, so I\ntried to fix them up myself.\n\nCould you take a look at it and see if the following is good\nenough, please?\n\n------------\nSubject: [PATCH] Return CURL error message when object transfer fails\nFrom: Nick Hengeveld <nickh@reactrix.com>\nDate: 1127757131 -0700\n\nReturn CURL error message when object transfer fails\n\n[jc: added similar curl_errorstr errors to places where we\n use curl_easy_perform() to run fetch that _must_ succeed.]\n\nSigned-off-by: Nick Hengeveld <nickh@reactrix.com>\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n\n---\n\n http-fetch.c |   24 ++++++++++++++++--------\n 1 files changed, 16 insertions(+), 8 deletions(-)\n\n4f1da6322aa5d11091005b23716bcc3c65151a32\ndiff --git a/http-fetch.c b/http-fetch.c\n--- a/http-fetch.c\n+++ b/http-fetch.c\n@@ -15,6 +15,7 @@\n \n static CURL *curl;\n static struct curl_slist *no_pragma_header;\n+static char curl_errorstr[CURL_ERROR_SIZE];\n \n static char *initial_base;\n \n@@ -112,10 +113,12 @@ static int fetch_index(struct alt_base *\n \tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);\n \tcurl_easy_setopt(curl, CURLOPT_URL, url);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \t\n \tif (curl_easy_perform(curl)) {\n \t\tfclose(indexfile);\n-\t\treturn error(\"Unable to get pack index %s\", url);\n+\t\treturn error(\"Unable to get pack index %s\\n%s\", url,\n+\t\t\t     curl_errorstr);\n \t}\n \n \tfclose(indexfile);\n@@ -264,10 +267,10 @@ static int fetch_indices(struct alt_base\n \tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n \tcurl_easy_setopt(curl, CURLOPT_URL, url);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \t\n-\tif (curl_easy_perform(curl)) {\n-\t\treturn -1;\n-\t}\n+\tif (curl_easy_perform(curl))\n+\t\treturn error(\"%s\", curl_errorstr);\n \n \twhile (i < buffer.posn) {\n \t\tswitch (data[i]) {\n@@ -327,10 +330,12 @@ static int fetch_pack(struct alt_base *r\n \tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);\n \tcurl_easy_setopt(curl, CURLOPT_URL, url);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);\n-\t\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n+\n \tif (curl_easy_perform(curl)) {\n \t\tfclose(packfile);\n-\t\treturn error(\"Unable to get pack file %s\", url);\n+\t\treturn error(\"Unable to get pack file %s\\n%s\", url,\n+\t\t\t     curl_errorstr);\n \t}\n \n \tfclose(packfile);\n@@ -373,6 +378,7 @@ int fetch_object(struct alt_base *repo, \n \tcurl_easy_setopt(curl, CURLOPT_FILE, NULL);\n \tcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_sha1_file);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, no_pragma_header);\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \n \turl = xmalloc(strlen(repo->base) + 50);\n \tstrcpy(url, repo->base);\n@@ -388,7 +394,7 @@ int fetch_object(struct alt_base *repo, \n \n \tif (curl_easy_perform(curl)) {\n \t\tunlink(filename);\n-\t\treturn -1;\n+\t\treturn error(\"%s\", curl_errorstr);\n \t}\n \n \tfchmod(local, 0444);\n@@ -453,6 +459,7 @@ int fetch_ref(char *ref, unsigned char *\n         curl_easy_setopt(curl, CURLOPT_FILE, &buffer);\n         curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);\n \tcurl_easy_setopt(curl, CURLOPT_HTTPHEADER, NULL);\n+\tcurl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errorstr);\n \n         url = xmalloc(strlen(base) + 6 + strlen(ref));\n         strcpy(url, base);\n@@ -464,7 +471,8 @@ int fetch_ref(char *ref, unsigned char *\n         curl_easy_setopt(curl, CURLOPT_URL, url);\n \n         if (curl_easy_perform(curl))\n-                return error(\"Couldn't get %s for %s\\n\", url, ref);\n+                return error(\"Couldn't get %s for %s\\n%s\",\n+\t\t\t     url, ref, curl_errorstr);\n \n         hex[40] = '\\0';\n         get_sha1_hex(hex, sha1);\n"},{"id":"9395","messageId":"20050927160740.GB1377@reactrix.com","threadId":"1951","inReplyTo":"7vpsqv2g3p.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH 3/3] Return CURL error message when object transfer fails","fromName":"Nick Hengeveld","fromEmail":"nickh@reactrix.com","sentAt":"2005-09-27T16:07:41Z","receivedAt":"2005-09-27T16:07:41Z","isPatch":true,"sender":{"key":"nickh@reactrix.com","avatar":null},"body":"On Mon, Sep 26, 2005 at 11:13:14PM -0700, Junio C Hamano wrote:\n\n> ... so the patch still needed some fixups.  It had minor\n> dependencies on the previous patches in the series as well, so I\n> tried to fix them up myself.\n> \n> Could you take a look at it and see if the following is good\n> enough, please?\n\nLooks great, thanks.\n\n> ------------\n> Subject: [PATCH] Return CURL error message when object transfer fails\n> From: Nick Hengeveld <nickh@reactrix.com>\n> Date: 1127757131 -0700\n> \n> Return CURL error message when object transfer fails\n> \n> [jc: added similar curl_errorstr errors to places where we\n>  use curl_easy_perform() to run fetch that _must_ succeed.]\n> \n> Signed-off-by: Nick Hengeveld <nickh@reactrix.com>\n> Signed-off-by: Junio C Hamano <junkio@cox.net>\n\n-- \nFor a successful technology, reality must take precedence over public\nrelations, for nature cannot be fooled.\n"}]}