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

[PATCH 4/7] trace: cosmetic fixes for error messages

From
Jeff King <peff@peff.net>
Date
Aug 3, 2016, 23:00 UTC
Message-ID
<20160803230022.drw4kcwgheeqn3xr@sigill.intra.peff.net>
In-Reply-To
<20160803225600.fgm23bdacunmrw44@sigill.intra.peff.net>

The error messages for the trace code are often multi-line; the first line gets a nice "warning:", but the rest are left-aligned. Let's give them an indentation to make sure they stand out as a unit.

While we're here, let's also downcase the first letter of each error (our usual style), and break up a long line of advice (since we're already using multiple lines, one more doesn't hurt).

We also replace "What does 'foo' for GIT_TRACE mean?". While cute, it's probably a good idea to give more context, and follow our usual styles. So it's now "unknown trace value for 'GIT_TRACE': foo".

Signed-off-by: Jeff King <peff@peff.net>
---
I went with an indent the size of "warning: ", because that string does
not actually get translated (it seems like it probably should, though).
I think it would be nicer to still to print:
 warning: first line
 warning: second line

etc. We do that for "advice:", but not the rest of the vreportf functions. It might be nice to do that, but we'd have to go back to printing into a buffer (since we can't break up the incoming format string that we feed to fprintf).

 trace.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/trace.c b/trace.c
index 6a77e4d..4d68eb5 100644
--- a/trace.c
+++ b/trace.c
@@ -61,8 +61,8 @@ static int get_trace_fd(struct trace_key *key)
 	else if (is_absolute_path(trace)) {
 		int fd = open(trace, O_WRONLY | O_APPEND | O_CREAT, 0666);
 		if (fd == -1) {
-			warning("Could not open '%s' for tracing: %s\n"
-				"Defaulting to tracing on stderr...",
+			warning("could not open '%s' for tracing: %s\n"
+				"         Defaulting to tracing on stderr...",
 				trace, strerror(errno));
 			key->fd = STDERR_FILENO;
 		} else {
@@ -70,11 +70,11 @@ static int get_trace_fd(struct trace_key *key)
 			key->need_close = 1;
 		}
 	} else {
-		warning("What does '%s' for %s mean?\n"
-			"If you want to trace into a file, then please set "
-			"%s to an absolute pathname (starting with /).\n"
-			"Defaulting to tracing on stderr...",
-			trace, key->key, key->key);
+		warning("unknown trace value for '%s': %s\n"
+			"         If you want to trace into a file, then please set %s\n"
+			"         to an absolute pathname (starting with /)\n"
+			"         Defaulting to tracing on stderr...",
+			key->key, trace, key->key);
 		key->fd = STDERR_FILENO;
 	}
 
@@ -93,7 +93,7 @@ void trace_disable(struct trace_key *key)
 	key->need_close = 0;
 }
 
-static const char err_msg[] = "Could not trace into fd given by "
+static const char err_msg[] = "could not trace into fd given by "
 	"GIT_TRACE environment variable";
 
 static int prepare_trace_line(const char *file, int line,
-- 
2.9.2.670.g42e63de
Previous: Jeff KingNext: Junio C Hamano
Message 17 of 20 in “minor trace fixes and cosmetic improvements”
  1. 0/7 minor trace fixes and cosmetic improvementsJeff King, Aug 3, 2016
  2. 2/7 trace: stop using write_or_whine_pipe()Jeff King, Aug 3, 2016
  3. 3/7 trace: use warning() for printing trace errorsJeff King, Aug 3, 2016
  4. Junio C HamanoAug 4, 2016
  5. Jeff KingAug 4, 2016
  6. Junio C HamanoAug 4, 2016
  7. Jeff KingAug 5, 2016
  8. Christian CouderAug 5, 2016
  9. Junio C HamanoAug 5, 2016
  10. 6/7 trace: disable key after write errorJeff King, Aug 3, 2016
  11. Junio C HamanoAug 4, 2016
  12. Jeff KingAug 4, 2016
  13. Jeff KingAug 5, 2016
  14. 7/7 write_or_die: drop write_or_whine_pipe()Jeff King, Aug 3, 2016
  15. 1/7 trace: handle NULL argument in trace_disable()Jeff King, Aug 3, 2016
  16. Jeff KingAug 3, 2016
  17. 4/7 trace: cosmetic fixes for error messagesJeff King, Aug 3, 2016
  18. Junio C HamanoAug 4, 2016
  19. Jeff KingAug 5, 2016
  20. 5/7 trace: correct variable name in write() error messageJeff King, Aug 3, 2016

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.