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

[PATCH 2/9] git_xmerge_config(): prefer error() to die()

From
Jeff King <peff@peff.net>
Date
Dec 7, 2023, 07:24 UTC
Message-ID
<20231207072449.GB1277973@coredump.intra.peff.net>
In-Reply-To
<20231207072338.GA1277727@coredump.intra.peff.net>

When parsing merge config, a few code paths die on error. It's preferable for us to call error() here, because the resulting error message from the config parsing code contains much more detail.

For example, before:
  fatal: unknown style 'bogus' given for 'merge.conflictstyle'
and after:
  error: unknown style 'bogus' given for 'merge.conflictstyle'
  fatal: bad config variable 'merge.conflictstyle' in file '.git/config' at line 7

Since we're touching these lines, I also marked them for translation. There's no reason they shouldn't behave like most other config-parsing errors.

Signed-off-by: Jeff King <peff@peff.net>
---
Before anyone mentions config_error_nonbool(), yes, the first hunk here
gets simplified to that in a later patch.
 xdiff-interface.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index adcea109fa..05d6475a09 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -1,4 +1,5 @@
 #include "git-compat-util.h"
+#include "gettext.h"
 #include "config.h"
 #include "hex.h"
 #include "object-store-ll.h"
@@ -313,7 +314,7 @@ int git_xmerge_config(const char *var, const char *value,
 {
 	if (!strcmp(var, "merge.conflictstyle")) {
 		if (!value)
-			die("'%s' is not a boolean", var);
+			return error(_("'%s' is not a boolean"), var);
 		if (!strcmp(value, "diff3"))
 			git_xmerge_style = XDL_MERGE_DIFF3;
 		else if (!strcmp(value, "zdiff3"))
@@ -325,8 +326,8 @@ int git_xmerge_config(const char *var, const char *value,
 		 * git-completion.bash when you add new merge config
 		 */
 		else
-			die("unknown style '%s' given for '%s'",
-			    value, var);
+			return error(_("unknown style '%s' given for '%s'"),
+				     value, var);
 		return 0;
 	}
 	return git_default_config(var, value, ctx, cb);
-- 
2.43.0.664.ga12c899002
Previous: Taylor BlauNext: Jeff King
Message 4 of 16 in “bonus config cleanups”
  1. 0/9 bonus config cleanupsJeff King, Dec 7, 2023
  2. 1/9 config: reject bogus values for core.checkstatJeff King, Dec 7, 2023
  3. Taylor BlauDec 8, 2023
  4. 2/9 git_xmerge_config(): prefer error() to die()Jeff King, Dec 7, 2023
  5. 3/9 imap-send: don't use git_die_config() inside callbackJeff King, Dec 7, 2023
  6. Patrick SteinhardtDec 7, 2023
  7. Taylor BlauDec 8, 2023
  8. Patrick SteinhardtDec 11, 2023
  9. Jeff KingDec 12, 2023
  10. 4/9 config: use config_error_nonbool() instead of custom messagesJeff King, Dec 7, 2023
  11. 5/9 diff: give more detailed messages for bogus diff.* configJeff King, Dec 7, 2023
  12. 6/9 config: use git_config_string() for core.checkRoundTripEncodingJeff King, Dec 7, 2023
  13. 7/9 push: drop confusing configset/callback redundancyJeff King, Dec 7, 2023
  14. 8/9 gpg-interface: drop pointless config_error_nonbool() checksJeff King, Dec 7, 2023
  15. 9/9 sequencer: simplify away extra git_config_string() callJeff King, Dec 7, 2023
  16. Patrick SteinhardtDec 7, 2023

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.