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

[PATCH 5/7] trace: correct variable name in write() error message

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

Our error message for write() always mentions GIT_TRACE, even though we may be writing for a different variable entirely. It's also not quite accurate to say "fd given by GIT_TRACE environment variable", as we may hit this error based on a filename the user put in the variable (we do complain and switch to stderr if the file cannot be opened, but it's still possible to hit a write() error on the descriptor later).

So let's fix those things, and switch to our more usual "unable to do X: Y" format for the error.

Signed-off-by: Jeff King <peff@peff.net>
---
 trace.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/trace.c b/trace.c
index 4d68eb5..4efb256 100644
--- a/trace.c
+++ b/trace.c
@@ -93,9 +93,6 @@ void trace_disable(struct trace_key *key)
 	key->need_close = 0;
 }
 
-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,
 			      struct trace_key *key, struct strbuf *buf)
 {
@@ -133,8 +130,11 @@ static int prepare_trace_line(const char *file, int line,
 
 static void trace_write(struct trace_key *key, const void *buf, unsigned len)
 {
-	if (write_in_full(get_trace_fd(key), buf, len) < 0)
-		warning("%s: write error (%s)", err_msg, strerror(errno));
+	if (write_in_full(get_trace_fd(key), buf, len) < 0) {
+		normalize_trace_key(&key);
+		warning("unable to write trace for %s: %s",
+			key->key, strerror(errno));
+	}
 }
 
 void trace_verbatim(struct trace_key *key, const void *buf, unsigned len)
-- 
2.9.2.670.g42e63de
Previous: Jeff King
Message 20 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.