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

[PATCH 5/9] diff: give more detailed messages for bogus diff.* config

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

The config callbacks for a few diff.* variables simply return -1 when we encounter an error. The message you get mentions the offending location, like:

  fatal: bad config variable 'diff.algorithm' in file '.git/config' at line 7

but is vague about "bad" (as it must be, since the message comes from the generic config code). Most callbacks add their own messages here, so let's do the same. E.g.:

  error: unknown value for config 'diff.algorithm': foo
  fatal: bad config variable 'diff.algorithm' in file '.git/config' at line 7

I've written the string in a way that should be reusable for translators, and matches another similar message in transport.c (there doesn't yet seem to be a popular generic message to reuse here, so hopefully this will get the ball rolling).

Note that in the case of diff.algorithm, our parse_algorithm_value() helper does detect a NULL value string. But it's still worth detecting it ourselves here, since we can give a more specific error message (and which is the usual one for unexpected implicit-bool values).

Signed-off-by: Jeff King <peff@peff.net>
---
 diff.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 5b213a4b44..a2def45644 100644
--- a/diff.c
+++ b/diff.c
@@ -445,9 +445,12 @@ int git_diff_ui_config(const char *var, const char *value,
 	}
 
 	if (!strcmp(var, "diff.algorithm")) {
+		if (!value)
+			return config_error_nonbool(var);
 		diff_algorithm = parse_algorithm_value(value);
 		if (diff_algorithm < 0)
-			return -1;
+			return error(_("unknown value for config '%s': %s"),
+				     var, value);
 		return 0;
 	}
 
@@ -486,7 +489,8 @@ int git_diff_basic_config(const char *var, const char *value,
 			return config_error_nonbool(var);
 		val = parse_ws_error_highlight(value);
 		if (val < 0)
-			return -1;
+			return error(_("unknown value for config '%s': %s"),
+				     var, value);
 		ws_error_highlight_default = val;
 		return 0;
 	}
-- 
2.43.0.664.ga12c899002
Previous: Jeff KingNext: Jeff King
Message 11 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.