-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: display response body on POST failure #1722
base: master
Are you sure you want to change the base?
Conversation
Welcome to GitGitGadgetHi @elhmn, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests. Please make sure that either:
You can CC potential reviewers by adding a footer to the PR description with the following syntax:
Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:
It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code. Contributing the patchesBefore you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form Both the person who commented An alternative is the channel
Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment If you want to see what email(s) would be sent for a After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail). If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the curl -g --user "<EMailAddress>:<Password>" \
--url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):
To send a new iteration, just add another PR comment with the contents: Need help?New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join. You may also be able to find help in real time in the developer IRC channel, |
There are issues in commit 6ce7244: |
0228b3f
to
ceccd3f
Compare
/allow |
User elhmn is now allowed to use GitGitGadget. WARNING: elhmn has no public email address set on GitHub; |
When Git sends a GET request and receives an HTTP code indicating failure (and that failure does not indicate an authentication problem), it shows the body of the response, i.e. the error message. The same is not true for POST requests. However, it would be good to show those error messages e.g. in the case of "429 Too many requests", because the user might otherwise be left puzzled about the reason why their clone did not work. This patch aligns the way POST requests are handled with the GET request handling. Signed-off-by: elhmn <elhmn@github.com>
ceccd3f
to
8cf756d
Compare
/preview |
Preview email sent as pull.1722.git.git.1716239101543.gitgitgadget@gmail.com |
/submit |
Submitted as pull.1722.git.git.1716239367046.gitgitgadget@gmail.com To fetch this version into
To fetch this version to local tag
|
On the Git mailing list, "brian m. carlson" wrote (reply to this): On 2024-05-20 at 21:09:26, Boris Mbarga via GitGitGadget wrote:
> From: elhmn <elhmn@github.com>
>
> When Git sends a GET request and receives an HTTP code indicating
> failure (and that failure does not indicate an authentication problem),
> it shows the body of the response, i.e. the error message.
> The same is not true for POST requests. However, it would be good to show
> those error messages e.g. in the case of "429 Too many requests", because
> the user might otherwise be left puzzled about the reason why their clone
> did not work.
I think this is a good idea (and not just because I talked about it with
Boris). If a user gets an error response, we want them to be able to
receive a helpful response from the server telling them what might have
gone wrong. While many of us know full well what a 429 response means,
it isn't immediately obvious to many users (judging from my experience
on Stack Overflow), and we might still want to tell users why they got a
429 (too many requests from their IP, network, token, application or
integration, etc.).
> This patch aligns the way POST requests are handled with the GET request
> handling.
>
> Signed-off-by: elhmn <elhmn@github.com>
I believe the policy is to put your real name here and in the commit. We
know what it is already from the headers. You can probably do `git -c
user.name="Boris Mbarga" commit --amend --reset-author --signoff` to fix
that.
> diff --git a/http.c b/http.c
> index 3d80bd6116e..2017e909054 100644
> --- a/http.c
> +++ b/http.c
> @@ -1419,6 +1419,7 @@ struct active_request_slot *get_active_slot(void)
> newslot->curl = NULL;
> newslot->in_use = 0;
> newslot->next = NULL;
> + newslot->errstr = NULL;
>
> slot = active_queue_head;
> if (!slot) {
> diff --git a/http.h b/http.h
> index 3af19a8bf53..cb542c62933 100644
> --- a/http.h
> +++ b/http.h
> @@ -30,6 +30,7 @@ struct active_request_slot {
> void *callback_data;
> void (*callback_func)(void *data);
> struct active_request_slot *next;
> + struct strbuf *errstr;
> };
>
> struct buffer {
> diff --git a/remote-curl.c b/remote-curl.c
> index 0b6d7815fdd..9b2a41b2451 100644
> --- a/remote-curl.c
> +++ b/remote-curl.c
> @@ -804,8 +804,11 @@ static size_t rpc_in(char *ptr, size_t eltsize,
> if (curl_easy_getinfo(data->slot->curl, CURLINFO_RESPONSE_CODE,
> &response_code) != CURLE_OK)
> return size;
> - if (response_code >= 300)
> + if (response_code >= 300) {
> + strbuf_reset(data->slot->errstr);
> + strbuf_add(data->slot->errstr, ptr, size);
> return size;
> + }
> if (size)
> data->rpc->any_written = 1;
> if (data->check_pktline)
> @@ -837,6 +840,8 @@ static int run_slot(struct active_request_slot *slot,
> strbuf_addch(&msg, ' ');
> strbuf_addstr(&msg, curl_errorstr);
> }
> + if (slot->errstr && slot->errstr->len)
> + error(_("%s"), slot->errstr->buf);
> }
> error(_("RPC failed; %s"), msg.buf);
I think we should print the "RPC failed" message as well, and first.
That message, even if not super helpful, contains the status code and
some other information, which might be more helpful than what the remote
server actually said.
We might also want to print "remote:" in front of the error string, so
that the user knows it comes from the server instead of Git. That can
be helpful when searching for it online.
--
brian m. carlson (they/them or he/him)
Toronto, Ontario, CA |
On the Git mailing list, Jeff King wrote (reply to this): On Mon, May 20, 2024 at 09:09:26PM +0000, Boris Mbarga via GitGitGadget wrote:
> From: elhmn <elhmn@github.com>
>
> When Git sends a GET request and receives an HTTP code indicating
> failure (and that failure does not indicate an authentication problem),
> it shows the body of the response, i.e. the error message.
Hmm, do we always do so? Long ago, I implemented that for the initial
HTTP connection in 426e70d4a1 (remote-curl: show server content on http
errors, 2013-04-05). That disables CURLOPT_FAILONERROR for that request,
and then shows the result even if we saw an error.
After that, we turned off CURLOPT_FAILONERROR for all requests in
e6cf87b12d (http: enable keep_error for HTTP requests, 2019-01-10), with
the rationale that we'd show them with GIT_CURL_VERBOSE (and presumably
GIT_TRACE_CURL, too). But do we actually write them out in most cases?
I'm not opposed to doing so, but just trying to understand what the
implications might be (and whether we are really bringing POSTs in line,
or if this is a new area).
In particular...
> @@ -837,6 +840,8 @@ static int run_slot(struct active_request_slot *slot,
> strbuf_addch(&msg, ' ');
> strbuf_addstr(&msg, curl_errorstr);
> }
> + if (slot->errstr && slot->errstr->len)
> + error(_("%s"), slot->errstr->buf);
> }
> error(_("RPC failed; %s"), msg.buf);
> strbuf_release(&msg);
If I understand correctly, slot->errstr is just the raw body content
returned by the request. That _might_ be something human-readable, but
it might not. For that initial connection, we have show_http_message(),
which shows only messages that come back as text/plain, does some light
cleanup, and shows the error with the "remote:" prefix. We'd want to use
that here, I'd think?
-Peff |
User |
CC: brian m. carlson sandals@crustytoothpaste.net, Johannes Schindelin johannes.schindelin@gmx.de
cc: Jeff King peff@peff.net