Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

elhmn
Copy link

@elhmn elhmn commented May 16, 2024

CC: brian m. carlson sandals@crustytoothpaste.net, Johannes Schindelin johannes.schindelin@gmx.de
cc: Jeff King peff@peff.net

Copy link

Welcome to GitGitGadget

Hi @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:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

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:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

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 patches

Before 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 /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

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 (raw) link), then import it into your mail program. If you use GMail, you can do this via:

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):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

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, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

Copy link

There are issues in commit 6ce7244:
remote-curl: display response body on POST failure
Lines in the body of the commit messages should be wrapped between 60 and 76 characters.
Indented lines, and lines without whitespace, are exempt

@elhmn elhmn force-pushed the display-rpc-post-err-message branch 2 times, most recently from 0228b3f to ceccd3f Compare May 16, 2024 13:44
@dscho
Copy link
Member

dscho commented May 16, 2024

/allow

Copy link

User elhmn is now allowed to use GitGitGadget.

WARNING: elhmn has no public email address set on GitHub;
GitGitGadget needs an email address to Cc: you on your contribution, so that you receive any feedback on the Git mailing list. Go to https://github.com/settings/profile to make your preferred email public to let GitGitGadget know which email address to use.

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>
@elhmn elhmn force-pushed the display-rpc-post-err-message branch from ceccd3f to 8cf756d Compare May 20, 2024 20:57
@elhmn elhmn changed the title remote-curl: display response body on POST failure http: display response body on POST failure May 20, 2024
@elhmn
Copy link
Author

elhmn commented May 20, 2024

/preview

Copy link

Preview email sent as pull.1722.git.git.1716239101543.gitgitgadget@gmail.com

@elhmn
Copy link
Author

elhmn commented May 20, 2024

/submit

Copy link

Submitted as pull.1722.git.git.1716239367046.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-1722/elhmn/display-rpc-post-err-message-v1

To fetch this version to local tag pr-git-1722/elhmn/display-rpc-post-err-message-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-1722/elhmn/display-rpc-post-err-message-v1

Copy link

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

Copy link

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

Copy link

User Jeff King <peff@peff.net> has been added to the cc: list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants