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

Re: [PATCH v2] launch_editor: waiting message on error

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 9, 2024, 01:27 UTC
Message-ID
<xmqq4jcb495u.fsf@gitster.g>
In-Reply-To
<0258a583-a90a-4434-bb4e-a1672d574b9c@gmail.com>
Rubén Justo <rjusto@gmail.com> writes:
> However, even with a short message, feeding that LF makes the following
> "error: There was a problem with the..." clearer, separating it from
> possible messages that the editor could have printed.  So, add that LF.
Sounds sensible.
Show 7 quoted lines
> +		if (print_waiting_for_editor && !is_terminal_dumb()) {
> +			if (!ret)
> +				/*
> +				 * Erase the entire line to avoid wasting
> +				 * the vertical space.
> +				 */
> +				term_clear_line();

I know this was inherited from the original, but overly verbose comment is not being very useful here.

Show 7 quoted lines
> +			else
> +				/*
> +				 * We don't want term_clear_line() here
> +				 * because the editor could have written
> +				 * some useful messages to the user.
> +				 */
> +				fprintf(stderr, "\n");

But I do not think this is emitting the newline at the right place. The sequence would be (1) we say "we are waiting" on an incomplete line, and then (2) the editor may say "There was a problem" without first adding LF _before_ saying so. Isn't adding a LF here too late to let the editor emit its message on its own line, instead of having it _after_ the short "hint" message?

Of course, after these two messages (one from us, and then the error message from the editor) concatenated on the same line, we would want to have the next error message on its own line, but do we need to add an extra newline here for that purpose? Unlike our "hint: we are waiting" that we fully intend to clean-up by using term_clear_line(), the editor that exits upon failure has no reason to keep its final error message "There was a problem" on an incomplete line without emitting the terminating LF before giving control back to us.

The "I do not know if it is bad enough to have these two on the same line" you seem to refer to indirectly by citing Lars's message <20171127134716.69471-1-lars.schneider@autodesk.com> is my <20171127134716.69471-1-lars.schneider@autodesk.com>, I think. But in that utterance, "these two" refers to "hint: we are waiting..." and whatever the message the editor emits upon seeing an error. The suggestion I made 7 years ago has nothing to do with the behaviour change this patch is making.

I think the code is doing the right thing. It is doing something different from what the proposed commit log message said it is doing. Let me try to summarize what I think this patch does:

	When advice.waitingForEditor configuration is not set to
	false, we show a hint telling that we are waiting for user's
	editor to close the file when we launch an editor and wait
	for it to return control back to us.  We give the message on
	an incomplete line, expecting that we can go back to the
	line and clear the message when the editor returns
	successfully.
	However, it is possible that the editor exits with an error
	status, in which case we show an error message and then
	return to our caller.  In such a case, the error message is
	given where the terminal cursor happens to be, which is most
	likely after the "we are waiting for your editor" message on
	the same line.
	Only clear the line when the editor returned cleanly, and
	otherwise, complete the message on the incomplete line with
	a newline before giving the error message.

Hopefully the above is a more reasonable explanation of what is happening in this patch, I think?

Actually, having thought it through in order to write the above explanation, I wonder if we can just call term_clear_line() regardless of the value of ret. Either case, the waiting is already over and in the error case, we show another message after it.

There is another error message when we fail to start the editor. Doesn't that codepath have the same problem?

I wonder:
 - moving the code to show "hint" down below start_command() where
   it could return error("unable to start");
 - moving the "if (ret) return error("There was a problem")" after
   the block that calls term_clear_line();
would be a better and sufficient fix?
Thanks.
Previous: Rubén JustoNext: Rubén Justo
Message 4 of 26 in “launch_editor: waiting message on error”
  1. launch_editor: waiting message on errorRubén Justo, Apr 8, 2024
  2. launch_editor: waiting message on errorRubén Justo, Apr 8, 2024
  3. launch_editor: waiting message on errorRubén Justo, Apr 8, 2024
  4. Junio C HamanoApr 9, 2024
  5. Rubén JustoApr 9, 2024
  6. Junio C HamanoApr 10, 2024
  7. Rubén JustoApr 11, 2024
  8. Junio C HamanoApr 12, 2024
  9. Rubén JustoApr 12, 2024
  10. Junio C HamanoApr 12, 2024
  11. Rubén JustoApr 12, 2024
  12. 0/2 launch_editor: waiting messageRubén Justo, Apr 12, 2024
  13. 1/2 launch_editor: waiting for editor messageRubén Justo, Apr 12, 2024
  14. rsbecker@nexbridge.comApr 12, 2024
  15. Rubén JustoApr 12, 2024
  16. rsbecker@nexbridge.comApr 12, 2024
  17. Phillip WoodApr 13, 2024
  18. 2/2 launch_editor: waiting message on errorRubén Justo, Apr 12, 2024
  19. Phillip WoodApr 13, 2024
  20. Rubén JustoApr 14, 2024
  21. launch_editor: waiting message on errorRubén Justo, Apr 14, 2024
  22. Phillip WoodApr 15, 2024
  23. Rubén JustoApr 15, 2024
  24. Junio C HamanoApr 15, 2024
  25. Rubén JustoApr 15, 2024
  26. Junio C HamanoApr 15, 2024

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.