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

Re: [PATCH 01/11] revert: Avoid calling die; return error instead

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 11, 2011, 20:26 UTC
Message-ID
<7vvcykv8j7.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1302448317-32387-2-git-send-email-artagnon@gmail.com>
Ramkumar Ramachandra <artagnon@gmail.com> writes:
> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>

You would need to write a lot more than that to justify why this is a good change and does not regress the existing codepaths. The above Subject: implies as if all you did was to replace "die()" with "return error()", but I am sure that you would also have audited all the existing callers of the affected codepaths and either they already handled an error return correctly by dying or exiting with non-zero status, or you adjusted them to expect an error return and exit with 129 in this patch.

Also we know from the context of this post that you are planning to add new callsites to some of the functions that are converted to give an error return with this patch, but it is nevertheless a good idea to briefly mention that (just "the codepath to implement new nitfol feature will be making calls to xyzzy and frotz and it does not want these to die; rather it wants to handle error cases itself" would do).

Show 7 quoted lines
> @@ -331,7 +331,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
>  	    (write_cache(index_fd, active_cache, active_nr) ||
>  	     commit_locked_index(&index_lock)))
>  		/* TRANSLATORS: %s will be "revert" or "cherry-pick" */
> -		die(_("%s: Unable to write new index file"), me);
> +		return error(_("%s: Unable to write new index file"), me);
>  	rollback_lock_file(&index_lock);

Do the callers rollback the lockfile in their error return codepaths now? Should they? If not why not?

One acceptable answer is "the only thing the current callers do in their error codepaths is to exit(129), and that will roll it back for us", but then that might mean this patch made the API more error prone to use when the next callsite you add wants to do more than just exitting.

Show 15 quoted lines
> @@ -397,18 +397,18 @@ static int do_pick_commit(void)
>  		 * to work on.
>  		 */
>  		if (write_cache_as_tree(head, 0, NULL))
> -			die (_("Your index file is unmerged."));
> +			return error(_("Your index file is unmerged."));
>  	} else {
>  		if (get_sha1("HEAD", head))
> -			die (_("You do not have a valid HEAD"));
> +			return error(_("You do not have a valid HEAD"));
>  		if (index_differs_from("HEAD", 0))
> -			die_dirty_index(me);
> +			return error_dirty_index(me);
>  	}
>  	discard_cache();

Likewise for this "discard-cache". Should it be the responsibility to the caller to discard the in-core cache when they handle an error return and possibly take an alternative action, or should this function be the one to do so for them?

Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 5 of 36 in “Sequencer Foundations”
  1. 00/11 Sequencer FoundationsRamkumar Ramachandra, Apr 10, 2011
  2. 01/11 revert: Avoid calling die; return error insteadRamkumar Ramachandra, Apr 10, 2011
  3. Jonathan NiederApr 10, 2011
  4. Ramkumar RamachandraMay 8, 2011
  5. Junio C HamanoApr 11, 2011
  6. 02/11 revert: Lose global variables "commit" and "me"Ramkumar Ramachandra, Apr 10, 2011
  7. Christian CouderApr 11, 2011
  8. Ramkumar RamachandraApr 11, 2011
  9. 03/11 revert: Introduce a struct to parse command-line options intoRamkumar Ramachandra, Apr 10, 2011
  10. Jonathan NiederApr 10, 2011
  11. Ramkumar RamachandraMay 8, 2011
  12. Junio C HamanoApr 11, 2011
  13. Ramkumar RamachandraMay 8, 2011
  14. 04/11 revert: Separate cmdline argument handling from the functional codeRamkumar Ramachandra, Apr 10, 2011
  15. 05/11 revert: Catch incompatible command-line options earlyRamkumar Ramachandra, Apr 10, 2011
  16. Junio C HamanoApr 11, 2011
  17. Ramkumar RamachandraMay 8, 2011
  18. 06/11 revert: Implement parsing --continue, --abort and --skipRamkumar Ramachandra, Apr 10, 2011
  19. 07/11 revert: Handle conflict resolutions more elegantlyRamkumar Ramachandra, Apr 10, 2011
  20. 08/11 usage: Introduce error_errno correspoding to die_errnoRamkumar Ramachandra, Apr 10, 2011
  21. 09/11 revert: Write head, todo, done filesRamkumar Ramachandra, Apr 10, 2011
  22. 10/11 revert: Give noop a default value while argument parsingRamkumar Ramachandra, Apr 10, 2011
  23. 11/11 revert: Implement --abort processingRamkumar Ramachandra, Apr 10, 2011
  24. Daniel BarkalowApr 10, 2011
  25. Ramkumar RamachandraApr 11, 2011
  26. Jonathan NiederApr 10, 2011
  27. Daniel BarkalowApr 11, 2011
  28. Jonathan NiederApr 11, 2011
  29. Ramkumar RamachandraApr 11, 2011
  30. Christian CouderApr 11, 2011
  31. Ramkumar RamachandraApr 11, 2011
  32. Christian CouderApr 11, 2011
  33. Ramkumar RamachandraApr 11, 2011
  34. Daniel BarkalowApr 11, 2011
  35. Jonathan NiederApr 11, 2011
  36. Daniel BarkalowApr 11, 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.