summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2013-09-08 08:38:22 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-09-09 18:07:07 (GMT)
commit2f666581bbc1895cf66a7007fb222026b299deb9 (patch)
tree7a5dd7bdbfc6f99a060ec263330a21184c26a34a /config.c
parent33fdd77e2b8ece3490982f9a35c8669d16879ba8 (diff)
downloadgit-2f666581bbc1895cf66a7007fb222026b299deb9.zip
git-2f666581bbc1895cf66a7007fb222026b299deb9.tar.gz
git-2f666581bbc1895cf66a7007fb222026b299deb9.tar.bz2
config: make numeric parsing errors more clear
If we try to parse an integer config argument and get a number outside of the representable range, we die with the cryptic message: "bad config value for '%s'". We can improve two things: 1. Show the value that produced the error (e.g., bad config value '3g' for 'foo.bar'). 2. Mention the reason the value was rejected (e.g., "invalid unit" versus "out of range"). A few tests need to be updated with the new output, but that should not be representative of real-world breakage, as scripts should not be depending on the exact text of our stderr output, which is subject to i18n anyway. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'config.c')
-rw-r--r--config.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/config.c b/config.c
index 9a42ad2..4be6c7b 100644
--- a/config.c
+++ b/config.c
@@ -543,18 +543,25 @@ int git_parse_ulong(const char *value, unsigned long *ret)
return 1;
}
-static void die_bad_config(const char *name)
+static void die_bad_number(const char *name, const char *value)
{
+ const char *reason = errno == ERANGE ?
+ "out of range" :
+ "invalid unit";
+ if (!value)
+ value = "";
+
if (cf && cf->name)
- die("bad config value for '%s' in %s", name, cf->name);
- die("bad config value for '%s'", name);
+ die("bad numeric config value '%s' for '%s' in %s: %s",
+ value, name, cf->name, reason);
+ die("bad numeric config value '%s' for '%s': %s", value, name, reason);
}
int git_config_int(const char *name, const char *value)
{
int ret;
if (!git_parse_int(value, &ret))
- die_bad_config(name);
+ die_bad_number(name, value);
return ret;
}
@@ -562,7 +569,7 @@ unsigned long git_config_ulong(const char *name, const char *value)
{
unsigned long ret;
if (!git_parse_ulong(value, &ret))
- die_bad_config(name);
+ die_bad_number(name, value);
return ret;
}