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

Re: [PATCH] usage: try harder to format very long error messages

From
Jeff King <peff@peff.net>
Date
Aug 11, 2015, 16:33 UTC
Message-ID
<20150811163355.GA15521@sigill.intra.peff.net>
In-Reply-To
<CAGZ79kbL6DuXoQi72z_5=PZy2+HPh_L4+FJ_diokJi6s3uP57g@mail.gmail.com>
On Tue, Aug 11, 2015 at 09:28:34AM -0700, Stefan Beller wrote:
Show 11 quoted lines
> On Tue, Aug 11, 2015 at 9:17 AM, Jeff King <peff@peff.net> wrote:
> > We use a fixed-size buffer of 4096 bytes to format die() and
> > error() messages. We explicitly avoided using a strbuf or
> > other fanciness here, because we want to make sure that we
> > report the message even in the face of malloc() failure
> > (after all, we might even be dying due to a malloc call).
> 
> Would it make sense to allocate memory in the early startup phase
> for a possible error message?
> So instead of putting 4kb on the stack we'd just have an unused 16kb
> on the heap.

Isn't that just punting on the problem? Now your 16kb filename will get truncated messages (in general we cannot even work with such files, but it is nice if the error message telling us so is readable).

If stack space is the problem, we can just put 16kb in BSS. But I think we really do want something that grows to the appropriate size. Or we need to start being more clever about our truncation. E.g., printing:

  error: unable to stat 'aaaaaaaaa[...]aaaaaa/foo': File too long

where the "[...]" is literally what we would print. The trouble with that approach is that it is hard to intercept large strings without re-implementing all of stdio's formatting.

-Peff
Previous: Stefan BellerNext: Junio C Hamano
Message 3 of 7 in “usage: try harder to format very long error messages”
  1. usage: try harder to format very long error messagesJeff King, Aug 11, 2015
  2. Stefan BellerAug 11, 2015
  3. Jeff KingAug 11, 2015
  4. Junio C HamanoAug 11, 2015
  5. Jeff KingAug 11, 2015
  6. 1/2 vreportf: report to arbitrary filehandlesJeff King, Aug 11, 2015
  7. 2/2 vreportf: avoid intermediate bufferJeff King, Aug 11, 2015

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.