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

Re: [PATCH 05/17] revert: Propogate errors upwards from do_pick_commit

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jul 19, 2011, 10:09 UTC
Message-ID
<CALkWK0ntcPR5y6m3O6SoTc_8B3xi4dsKFs6zFMJrcwOtRQoQbA@mail.gmail.com>
In-Reply-To
<20110717165904.GA27787@elie>
Hi,
Jonathan Nieder writes:
Show 14 quoted lines
> Ramkumar Ramachandra wrote:
>> revert: Propogate errors upwards from do_pick_commit
>>
>> Currently, revert_or_cherry_pick can fail in two ways.  If it
>> encounters a conflict, it returns a positive number indicating the
>> intended exit status for the git wrapper to pass on; for all other
>> errors, it calls die().  The latter behavior is inconsiderate towards
>> callers, as it denies them the opportunity to do some post-processing
>> or cleanup before exiting.  For instance, later in the series, callers
>> will want to save some data about the current operation before
>> exiting.
>
> Thanks for explaining.  Why can't callers use set_die_routine() or
> atexit()?  Is the last sentence true?

Definitely a misguided commit message. New commit message.

revert: Propogate errors upwards from do_pick_commit

Currently, revert_or_cherry_pick can fail in two ways. If it encounters a conflict, it returns a positive number indicating the intended exit status for the git wrapper to pass on; for all other errors, it calls die(). The latter behavior is inconsiderate towards callers, as it denies them the opportunity to recover from errors and do other things.

After this patch, revert_or_cherry_pick will still return a positive return value to indicate an exit status for conflicts as before, while for some other errors, it will print an error message and return -1 instead of die()-ing. The cmd_revert and cmd_cherry_pick are adjusted to handle the fatal errors by die()-ing themselves.

While the full benefits of this patch will only be seen once all the "die" calls are replaced with calls to "error", its immediate impact is to change some "fatal:" messages to say "error:" and to add a new "fatal: cherry-pick failed" message at the end when the operation fails.

Show 9 quoted lines
>  Since no callers take advantage of the ability to recover from
>  errors yet, it is possible and even likely that these functions do
>  not completely clean up after themselves on (fatal) error but leave
>  some state to be cleared away by exit().  Callers beware!
>
> That last paragraph summarizes my worry.  Since this API change does
> not seem to be used by the other patches, I would prefer not to
> leave such a trap for unwary new callers, at least until the intended
> legitimate use is a little clearer.

Very legitimate. Thanks for explaining. However, I don't think I've introduced any new traps for callers except for the write_cache_as_tree() thing which is fixed now -- so, I've omitted your warning in the commit message because I'm not entirely sure it's true. Yes, we don't have callers that take advantage of this yet, but the idea of the patch is to work in the right direction -- we have to convert all the "die" calls to "error" calls and make a nice public API out of it sometime in the future.

Also, should we worry about it so much at this stage? We haven't set up a public API

Show 11 quoted lines
>>> write_cache_as_tree() locks the index and does not always commit or
>>> roll it back except on success.  Current callers aren't likely to try
>>> to lock the index again (since they just die()), but presumably the
>>> goal of returning error() here is to allow for callers that want to
>>> stay alive and do something more.  How should they recover (i.e., what
>>> is the intended API)?
>>
>> Hm, there was supposed to be a discard_cache() before this error as I
>> recall -- fixed now.  Thanks for catching.
>
> discard_index() does not unlock the index.

Ugh, sorry. I realize now that you were talking about the lockfile, which will only be cleaned up by exit(). I thought about this for a while and decided to classify this as an unrecoverable error for the moment -- we have no way to clean up the lockfile at this stage, so might as well die() instead of setting a trap for callers.

Show 24 quoted lines
>>> Similar questions probably apply to calls to other APIs that return -1
>>> to mean "I failed; please print an appropriate message about that and
>>> exit".  I haven't checked carefully, since the answer to this example
>>> could help in knowing what to look for in the others.
>>
>> I think the others are fairly clear actually.
>
> Roughly speaking, there are two kinds of functions that return error()
> instead of die()-ing in the git codebase:
>
>  1. Those that recover from their errors, leaving the process in a
>    sane state that allows the caller (e.g., a long-lived interactive
>    porcelain) to go on to do other things
>
>  2. Those that do not have enough information to give a useful error
>    message themselves, so delegate to the caller the responsibility
>    to die() with an error message about where in the program the
>    failure occured.
>
> The commit message suggests that you are introducing a new category:
>
>  3. Those that could die() without trouble, _except_ that some callers
>    want to do cleanup of private state on exit and atexit() is not
>    working for them for some reason

Thanks for the excellent categorization -- this change falls mostly in category (1), and a little bit in (2) too. When we work towards a general sequencer, do_pick_commit has no idea about the name of git wrapper that invoked it ("git cherry-pick" or "git revert" in this case). Thinking about these things helped me write a better commit message.

Thanks.
-- Ram
Previous: Jonathan NiederNext: Ramkumar Ramachandra
Message 24 of 99 in “[GSoC update] Sequencer for inclusion”
  1. Ramkumar RamachandraJul 11, 2011
  2. 01/17 advice: Introduce error_resolve_conflictRamkumar Ramachandra, Jul 11, 2011
  3. 02/17 revert: Inline add_message_to_msg functionRamkumar Ramachandra, Jul 11, 2011
  4. Jonathan NiederJul 12, 2011
  5. Ramkumar RamachandraJul 13, 2011
  6. Jonathan NiederJul 13, 2011
  7. Ramkumar RamachandraJul 19, 2011
  8. Junio C HamanoJul 19, 2011
  9. Ramkumar RamachandraJul 19, 2011
  10. Jonathan NiederJul 19, 2011
  11. Ramkumar RamachandraJul 20, 2011
  12. 03/17 revert: Don't check lone argument in get_encodingRamkumar Ramachandra, Jul 11, 2011
  13. Jonathan NiederJul 12, 2011
  14. Ramkumar RamachandraJul 13, 2011
  15. Jonathan NiederJul 13, 2011
  16. 04/17 revert: Rename no_replay to record_originRamkumar Ramachandra, Jul 11, 2011
  17. Jonathan NiederJul 12, 2011
  18. Ramkumar RamachandraJul 13, 2011
  19. Jonathan NiederJul 17, 2011
  20. 05/17 revert: Propogate errors upwards from do_pick_commitRamkumar Ramachandra, Jul 11, 2011
  21. Jonathan NiederJul 12, 2011
  22. Ramkumar RamachandraJul 17, 2011
  23. Jonathan NiederJul 17, 2011
  24. Ramkumar RamachandraJul 19, 2011
  25. 06/17 revert: Eliminate global "commit" variableRamkumar Ramachandra, Jul 11, 2011
  26. Jonathan NiederJul 12, 2011
  27. Ramkumar RamachandraJul 13, 2011
  28. Jonathan NiederJul 13, 2011
  29. Ramkumar RamachandraJul 13, 2011
  30. Jonathan NiederJul 13, 2011
  31. 07/17 revert: Introduce struct to keep command-line optionsRamkumar Ramachandra, Jul 11, 2011
  32. Jonathan NiederJul 12, 2011
  33. Ramkumar RamachandraJul 13, 2011
  34. 08/17 revert: Separate cmdline parsing from functional codeRamkumar Ramachandra, Jul 11, 2011
  35. Jonathan NiederJul 12, 2011
  36. Ramkumar RamachandraJul 18, 2011
  37. Jonathan NiederJul 18, 2011
  38. 09/17 revert: Don't create invalid replay_opts in parse_argsRamkumar Ramachandra, Jul 11, 2011
  39. Junio C HamanoJul 11, 2011
  40. Ramkumar RamachandraJul 12, 2011
  41. Jonathan NiederJul 12, 2011
  42. Ramkumar RamachandraJul 17, 2011
  43. Jonathan NiederJul 17, 2011
  44. 10/17 sequencer: Announce sequencer state locationRamkumar Ramachandra, Jul 11, 2011
  45. Jonathan NiederJul 12, 2011
  46. Sverre RabbelierJul 13, 2011
  47. Ramkumar RamachandraJul 17, 2011
  48. Jonathan NiederJul 17, 2011
  49. Ramkumar RamachandraJul 18, 2011
  50. 11/17 revert: Save data for continuing after conflict resolutionRamkumar Ramachandra, Jul 11, 2011
  51. Junio C HamanoJul 11, 2011
  52. Junio C HamanoJul 11, 2011
  53. Ramkumar RamachandraJul 12, 2011
  54. Jonathan NiederJul 12, 2011
  55. Ramkumar RamachandraJul 17, 2011
  56. Jonathan NiederJul 17, 2011
  57. Ramkumar RamachandraJul 18, 2011
  58. Jonathan NiederJul 19, 2011
  59. Ramkumar RamachandraJul 19, 2011
  60. 12/17 revert: Save command-line options for continuing operationRamkumar Ramachandra, Jul 11, 2011
  61. Junio C HamanoJul 11, 2011
  62. Ramkumar RamachandraJul 12, 2011
  63. Jonathan NiederJul 12, 2011
  64. Ramkumar RamachandraJul 18, 2011
  65. 13/17 revert: Introduce a layer of indirection over pick_commitsRamkumar Ramachandra, Jul 11, 2011
  66. Jonathan NiederJul 12, 2011
  67. Ramkumar RamachandraJul 18, 2011
  68. 14/17 reset: Make hard reset remove the sequencer stateRamkumar Ramachandra, Jul 11, 2011
  69. Jonathan NiederJul 12, 2011
  70. Ramkumar RamachandraJul 17, 2011
  71. 15/17 revert: Remove sequencer state when no commits are pendingRamkumar Ramachandra, Jul 11, 2011
  72. Junio C HamanoJul 11, 2011
  73. Ramkumar RamachandraJul 12, 2011
  74. 16/17 revert: Introduce --reset to remove sequencer stateRamkumar Ramachandra, Jul 11, 2011
  75. Jonathan NiederJul 12, 2011
  76. Ramkumar RamachandraJul 17, 2011
  77. Jonathan NiederJul 17, 2011
  78. 17/17 revert: Introduce --continue to continue the operationRamkumar Ramachandra, Jul 11, 2011
  79. Jonathan NiederJul 12, 2011
  80. Ramkumar RamachandraJul 17, 2011
  81. Jonathan NiederJul 17, 2011
  82. Ramkumar RamachandraJul 18, 2011
  83. Jonathan NiederJul 18, 2011
  84. Jonathan NiederJul 11, 2011
  85. Ramkumar RamachandraJul 11, 2011
  86. Ramkumar RamachandraJul 11, 2011
  87. Jonathan NiederJul 11, 2011
  88. Ramkumar RamachandraJul 12, 2011
  89. Junio C HamanoJul 11, 2011
  90. Jeff KingJul 11, 2011
  91. Ramkumar RamachandraJul 12, 2011
  92. Jeff KingJul 12, 2011
  93. Ramkumar RamachandraJul 13, 2011
  94. Jeff KingJul 13, 2011
  95. config: Introduce functions to write non-standard fileRamkumar Ramachandra, Jul 18, 2011
  96. Junio C HamanoJul 18, 2011
  97. Ramkumar RamachandraJul 19, 2011
  98. Jonathan NiederJul 12, 2011
  99. Miles BaderJul 12, 2011

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.