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

Re: [PATCH] am: ignore return value of write_file()

From
Jeff King <peff@peff.net>
Date
Jul 8, 2016, 21:51 UTC
Message-ID
<20160708215114.GC9820@sigill.intra.peff.net>
In-Reply-To
<577FF48C.4030008@web.de>
On Fri, Jul 08, 2016 at 08:44:28PM +0200, René Scharfe wrote:
Show 14 quoted lines
> > The question is whether it makes sense for write_file() to die(). It is a
> > library function and not every caller can be happy with that function to
> > exit the program when some file could not be written, without a chance to
> > tell the user what to do about the situation.
> > 
> > If write_file() was defined in builtin/am.c, as a static function, I would
> > grudgingly acquiesce, but it is not.
> > 
> > IMO it would be better to fix write_file() to *not* die() but return
> > error() instead.
> 
> there is write_file_gently() for that purpose, but it's used only by a
> single caller that exits on failure after all, and in fact Peff's series
> drops it.

Yeah, I always feel funny going in the opposite direction of libification, as in this case. But having looked at the set of current and potential-to-convert callers, I couldn't find a single one which would want the gentle behavior. Any site which doesn't die also wanted something else more complex (e.g., different open options).

So I think rather than loading down write_file() with options that will make the simple callers harder to read, we are better off to keep its implementation simple, and let people call its building blocks easily.

And I think we already have that; in my final version it really is just xopen/write_in_full/close. So the non-simple sites can still make use of those components.

-Peff
Previous: René Scharfe
Message 27 of 27 in “am: ignore return value of write_file()”
  1. am: ignore return value of write_file()René Scharfe, Jul 7, 2016
  2. Jeff KingJul 7, 2016
  3. Johannes SchindelinJul 8, 2016
  4. Jeff KingJul 8, 2016
  5. 0/8 write_file cleanupsJeff King, Jul 8, 2016
  6. 1/8 config: fix bogus fd check when setting up default configJeff King, Jul 8, 2016
  7. 2/8 am: ignore return value of write_file()Jeff King, Jul 8, 2016
  8. 3/8 branch: use non-gentle write_file for branch descriptionJeff King, Jul 8, 2016
  9. 4/8 write_file: drop "gently" formJeff King, Jul 8, 2016
  10. 5/8 write_file: use xopenJeff King, Jul 8, 2016
  11. 6/8 write_file: add pointer+len variantJeff King, Jul 8, 2016
  12. 7/8 write_file: add format attributeJeff King, Jul 8, 2016
  13. Jeff KingJul 8, 2016
  14. 1/2 walker: let walker_say take arbitrary formatsJeff King, Jul 8, 2016
  15. 2/2 avoid using sha1_to_hex output as printf formatJeff King, Jul 8, 2016
  16. Jeff KingJul 8, 2016
  17. Junio C HamanoJul 8, 2016
  18. Junio C HamanoJul 8, 2016
  19. Jeff KingJul 8, 2016
  20. 8/8 use write_file_buf where applicableJeff King, Jul 8, 2016
  21. 9/8 branch: use write_file_buf instead of write_fileJeff King, Jul 8, 2016
  22. René ScharfeJul 8, 2016
  23. Johannes SchindelinJul 9, 2016
  24. Johannes SchindelinJul 10, 2016
  25. Johannes SchindelinJul 8, 2016
  26. René ScharfeJul 8, 2016
  27. Jeff KingJul 8, 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.