Skip to content

config: improve error message for boolean config#841

Closed
KlotzAndrew wants to merge 1 commit intogit:masterfrom
KlotzAndrew:better_bool_errors
Closed

config: improve error message for boolean config#841
KlotzAndrew wants to merge 1 commit intogit:masterfrom
KlotzAndrew:better_bool_errors

Conversation

@KlotzAndrew
Copy link
Copy Markdown
Contributor

@KlotzAndrew KlotzAndrew commented Sep 12, 2020

Currently invalid boolean config values return messages about 'bad
numeric', which I found misleading when the error was due to a
boolean string value. This change makes the error message reflect
the boolean value.

The current approach relies on GIT_TEST_GETTEXT_POISON
being a boolean value, moving its special case out from
die_bad_number() and into git_config_bool_or_int(). An
alternative could be for die_bad_number() to handle boolean
values when erroring, although the function name might need to
change if it is handling non-numeric values.

changes since v1

  • moved boolean error message change out of git_config_bool_or_int
    to just in git_config_bool and added die_bad_boolean instead of
    modifying die_bad_number.

changes since v2

  • added a test for boolean config values
  • changed the condition to hit die_bad_bool from if (0 <= v) to if (v < 0)
  • removed change in get-text-poison.sh test

Signed-off-by: Andrew Klotz agc.klotz@gmail.com

cc: Jeff King peff@peff.net
cc: Phillip Wood phillip.wood123@gmail.com

@gitgitgadget-git
Copy link
Copy Markdown

Welcome to GitGitGadget

Hi @KlotzAndrew, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that your Pull Request has a good description, as it will be used as cover letter.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "commit:", and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the FreeNode IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Freenode. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@KlotzAndrew KlotzAndrew force-pushed the better_bool_errors branch 3 times, most recently from dd17e4d to 2f791ac Compare September 12, 2020 22:06
@KlotzAndrew KlotzAndrew changed the title better error message for boolean config config: improve error message for boolean config Sep 12, 2020
@KlotzAndrew KlotzAndrew force-pushed the better_bool_errors branch 2 times, most recently from 8aac139 to 8a4fecf Compare September 12, 2020 22:22
@dscho
Copy link
Copy Markdown
Member

dscho commented Sep 14, 2020

/allow

@gitgitgadget-git
Copy link
Copy Markdown

User KlotzAndrew is now allowed to use GitGitGadget.

@KlotzAndrew
Copy link
Copy Markdown
Contributor Author

/preview

@gitgitgadget-git
Copy link
Copy Markdown

Preview email sent as pull.841.git.git.1600394430.gitgitgadget@gmail.com

@KlotzAndrew
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.841.git.git.1600395427.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git pr-git-841/KlotzAndrew/better_bool_errors-v1

To fetch this version to local tag pr-git-841/KlotzAndrew/better_bool_errors-v1:

git fetch --no-tags https://github.com/gitgitgadget/git tag pr-git-841/KlotzAndrew/better_bool_errors-v1

@gitgitgadget-git
Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Andrew Klotz via GitGitGadget" <gitgitgadget@gmail.com> writes:

> Currently invalid boolean config values return messages about 'bad numeric',
> which I found misleading when the error was due to a boolean string value.
> This change makes the error message reflect the boolean value.
>
> The current approach relies on GIT_TEST_GETTEXT_POISON being a boolean
> value, moving its special case out fromdie_bad_number() and into 
> git_config_bool_or_int().

The approach does not make anything worse than what we currently
have, which is good.

I am undecided if we want to apply 2/2, or if we want to apply 1/2
alone without 2/2.  If we applied 2/2, those who are reading the
code in a year who forgot about this review thread would have to
wonder if all values assigned to the variable bad_numeric are
enclosed in _() and go up to find all assignments.

Omitting 2/2 would keep _() around the message string fed to die(),
so it may be easier to immediately see that the call to die is not
missing basic i18n, but there is a risk to forget marking with N_().

If we were to use 2/2 in addition to 1/2, then squashing them into
one commit will make the result easier to follow, because we no
longer need an untranslated string in bad_numeric after 1/2 is
applied.  We are losing "the reason why we use N_() is..." comment
in 1/2 anyway so doing what 2/2 does in the same commit would be
more sensible than splitting these into two patches.

I dunno.

Thanks.

@@ -996,15 +996,6 @@ static void die_bad_number(const char *name, const char *value)
if (!value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Jeff King wrote (reply to this):

On Fri, Sep 18, 2020 at 02:17:06AM +0000, Andrew Klotz via GitGitGadget wrote:

> diff --git a/t/t0205-gettext-poison.sh b/t/t0205-gettext-poison.sh
> index f9fa16ad83..b66d34c6f2 100755
> --- a/t/t0205-gettext-poison.sh
> +++ b/t/t0205-gettext-poison.sh
> @@ -33,7 +33,7 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semant
>  
>  test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
>  	test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
> -	grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
> +	grep \"fatal: bad boolean config value 'xyz' for 'GIT_TEST_GETTEXT_POISON'\" error
>  "

This test is pretty subtle and depends on gettext-poison's inner
workings. I wonder if it's worth adding a separate:

  git config --bool --default=foo does.not.exist

test in t1300 or similar.

-Peff

@gitgitgadget-git
Copy link
Copy Markdown

User Jeff King <peff@peff.net> has been added to the cc: list.

@@ -996,15 +996,6 @@ static void die_bad_number(const char *name, const char *value)
if (!value)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Andrew

On 18/09/2020 03:17, Andrew Klotz via GitGitGadget wrote:
> From: Andrew Klotz <agc.klotz@gmail.com>
> 
> Currently invalid boolean config values return messages about 'bad
> numeric', which is slightly misleading when the error was due to a
> boolean value. We can improve the developer experience by returning a
> boolean error message when we know the value is neither a bool text or
> int.

This patch improves things for boolean config keys  but 
git_config_bool_or_int() is used by status.submoduleSummary, merge.log 
and commit.verbose which can be either a number or a boolean (where a 
boolean generally means use a default number). It would be a more 
invasive change but I wonder if it would be better for git_config_bool() 
to have it's own error message rather sharing it with 
git_config_bool_or_int().

Best Wishes

Phillip

> `GIT_TEST_GETTEXT_POISON` is a boolean so we no longer fail on
> evaluating it as an int in `git_config_int`. Because of that we can
> move the special translation case into the boolean config check where
> we are now failing with an updated message
> 
> before with an invalid boolean value of `non-boolean`, its unclear what
> numeric is referring to:
> ```
> fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
> ```
> 
> now the error message mentions `non-boolean` is a bad boolean value:
> ```
> fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
> ```
> 
> Signed-off-by: Andrew Klotz <agc.klotz@gmail.com>
> ---
>   config.c                  | 22 ++++++++++++----------
>   t/t0205-gettext-poison.sh |  2 +-
>   2 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/config.c b/config.c
> index 2bdff4457b..198d0d3216 100644
> --- a/config.c
> +++ b/config.c
> @@ -996,15 +996,6 @@ static void die_bad_number(const char *name, const char *value)
>   	if (!value)
>   		value = "";
>   
> -	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
> -		/*
> -		 * We explicitly *don't* use _() here since it would
> -		 * cause an infinite loop with _() needing to call
> -		 * use_gettext_poison(). This is why marked up
> -		 * translations with N_() above.
> -		 */
> -		die(bad_numeric, value, name, error_type);
> -
>   	if (!(cf && cf->name))
>   		die(_(bad_numeric), value, name, _(error_type));
>   
> @@ -1097,7 +1088,18 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>   		return v;
>   	}
>   	*is_bool = 0;
> -	return git_config_int(name, value);
> +	if (git_parse_int(value, &v))
> +		return v;
> +
> +	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
> +		/*
> +		 * We explicitly *don't* use _() here since it would
> +		 * cause an infinite loop with _() needing to call
> +		 * use_gettext_poison().
> +		 */
> +		die("bad boolean config value '%s' for '%s'", value, name);
> +	else
> +		die(_("bad boolean config value '%s' for '%s'"), value, name);
>   }
>   
>   int git_config_bool(const char *name, const char *value)
> diff --git a/t/t0205-gettext-poison.sh b/t/t0205-gettext-poison.sh
> index f9fa16ad83..b66d34c6f2 100755
> --- a/t/t0205-gettext-poison.sh
> +++ b/t/t0205-gettext-poison.sh
> @@ -33,7 +33,7 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semant
>   
>   test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
>   	test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
> -	grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
> +	grep \"fatal: bad boolean config value 'xyz' for 'GIT_TEST_GETTEXT_POISON'\" error
>   "
>   
>   test_done
> 

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Junio C Hamano wrote (reply to this):

Phillip Wood <phillip.wood123@gmail.com> writes:

> This patch improves things for boolean config keys  but
> git_config_bool_or_int() is used by status.submoduleSummary, merge.log 
> and commit.verbose which can be either a number or a boolean (where a
> boolean generally means use a default number).

Excellent point.  The rephrasing done by the patch as-is will be a
regression.

> It would be a more 
> invasive change but I wonder if it would be better for
> git_config_bool() to have it's own error message rather sharing it
> with git_config_bool_or_int().

You'd probably need a variant of die_bad_numer(), with an untested
patch like below.


 config.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/config.c b/config.c
index 8db9c77098..801d944d2b 100644
--- a/config.c
+++ b/config.c
@@ -1097,7 +1097,10 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
 		return v;
 	}
 	*is_bool = 0;
-	return git_config_int(name, value);
+
+	if (!git_parse_int(value, &v))
+		die_bad_number_or_bool(name, value);
+	return v;
 }
 
 int git_config_bool(const char *name, const char *value)

@gitgitgadget-git
Copy link
Copy Markdown

User Phillip Wood <phillip.wood123@gmail.com> has been added to the cc: list.

@KlotzAndrew
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.841.v2.git.git.1612833909210.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git pr-git-841/KlotzAndrew/better_bool_errors-v2

To fetch this version to local tag pr-git-841/KlotzAndrew/better_bool_errors-v2:

git fetch --no-tags https://github.com/gitgitgadget/git tag pr-git-841/KlotzAndrew/better_bool_errors-v2

@gitgitgadget-git
Copy link
Copy Markdown

On the Git mailing list, Jeff King wrote (reply to this):

On Tue, Feb 09, 2021 at 01:25:08AM +0000, Andrew Klotz via GitGitGadget wrote:

> Currently invalid boolean config values return messages about 'bad
> numeric', which is slightly misleading when the error was due to a
> boolean value. We can improve the developer experience by returning a
> boolean error message when we know the value is neither a bool text or
> int.

Thanks for keeping at this. The goal makes sense. The implementation
looks OK to me, but I had a few really tiny comments.

> before with an invalid boolean value of `non-boolean`, its unclear what
> numeric is referring to:
> ```
> fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
> ```
> 
> now the error message mentions `non-boolean` is a bad boolean value:
> ```
> fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
> ```

Our commit messages aren't generally formatted as markdown. So this
looks a little nicer using indentation (which also happens to generate
nice markdown output):

  numeric is referring to:

      fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit

  now the error message mentions `non-boolean` is a bad boolean value:

      fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'

Not worth a re-roll on its own, though.

> +NORETURN
> +static void die_bad_bool(const char *name, const char *value)
> +{
> +	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
> +		/*
> +		 * We explicitly *don't* use _() here since it would
> +		 * cause an infinite loop with _() needing to call
> +		 * use_gettext_poison().
> +		 */
> +		die("bad boolean config value '%s' for '%s'", value, name);
> +	else
> +		die(_("bad boolean config value '%s' for '%s'"), value, name);
> +}

The duplication is ugly, but I think it's the least-bad solution (and I
still dream that GETTEXT_POISON may one day go away :) ).

> @@ -1102,8 +1116,11 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>  
>  int git_config_bool(const char *name, const char *value)
>  {
> -	int discard;
> -	return !!git_config_bool_or_int(name, value, &discard);
> +	int v = git_parse_maybe_bool(value);
> +	if (0 <= v)
> +		return v;
> +	else
> +		die_bad_bool(name, value);

I had to look at this a minute to be sure we always returned a value.
But the compiler knows that die_bad_bool() doesn't return, and that we
always take one of the two conditionals.

I do think it might be easier to read as:

  int v = git_parse_maybe_bool(value);
  if (v < 0)
          die_bad_bool(name, value);
  return v;

but I admit that's nit-picking.

> diff --git a/t/t0205-gettext-poison.sh b/t/t0205-gettext-poison.sh
> index f9fa16ad8363..b66d34c6f2bc 100755
> --- a/t/t0205-gettext-poison.sh
> +++ b/t/t0205-gettext-poison.sh
> @@ -33,7 +33,7 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semant
>  
>  test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
>  	test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
> -	grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
> +	grep \"fatal: bad boolean config value 'xyz' for 'GIT_TEST_GETTEXT_POISON'\" error
>  "

Do we want a separate test in t1300 that doesn't rely on GETTEXT_POISON
continuing to hang around (the idea has been thrown around elsewhere of
it maybe going away entirely)?

-Peff

@gitgitgadget-git
Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

Jeff King <peff@peff.net> writes:

> On Tue, Feb 09, 2021 at 01:25:08AM +0000, Andrew Klotz via GitGitGadget wrote:
>
>> Currently invalid boolean config values return messages about 'bad
>> numeric', which is slightly misleading when the error was due to a
>> boolean value. We can improve the developer experience by returning a
>> boolean error message when we know the value is neither a bool text or
>> int.
>
> Thanks for keeping at this. The goal makes sense. The implementation
> looks OK to me, but I had a few really tiny comments.
>
>> before with an invalid boolean value of `non-boolean`, its unclear what
>> numeric is referring to:
>> ```
>> fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
>> ```
>> 
>> now the error message mentions `non-boolean` is a bad boolean value:
>> ```
>> fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
>> ```
>
> Our commit messages aren't generally formatted as markdown. So this
> looks a little nicer using indentation (which also happens to generate
> nice markdown output):
>
>   numeric is referring to:
>
>       fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
>
>   now the error message mentions `non-boolean` is a bad boolean value:
>
>       fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
>
> Not worth a re-roll on its own, though.
>
>> +NORETURN
>> +static void die_bad_bool(const char *name, const char *value)
>> +{
>> +	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
>> +		/*
>> +		 * We explicitly *don't* use _() here since it would
>> +		 * cause an infinite loop with _() needing to call
>> +		 * use_gettext_poison().
>> +		 */
>> +		die("bad boolean config value '%s' for '%s'", value, name);
>> +	else
>> +		die(_("bad boolean config value '%s' for '%s'"), value, name);
>> +}
>
> The duplication is ugly, but I think it's the least-bad solution (and I
> still dream that GETTEXT_POISON may one day go away :) ).
>
>> @@ -1102,8 +1116,11 @@ int git_config_bool_or_int(const char *name, const char *value, int *is_bool)
>>  
>>  int git_config_bool(const char *name, const char *value)
>>  {
>> -	int discard;
>> -	return !!git_config_bool_or_int(name, value, &discard);
>> +	int v = git_parse_maybe_bool(value);
>> +	if (0 <= v)
>> +		return v;
>> +	else
>> +		die_bad_bool(name, value);
>
> I had to look at this a minute to be sure we always returned a value.
> But the compiler knows that die_bad_bool() doesn't return, and that we
> always take one of the two conditionals.
>
> I do think it might be easier to read as:
>
>   int v = git_parse_maybe_bool(value);
>   if (v < 0)
>           die_bad_bool(name, value);
>   return v;
>
> but I admit that's nit-picking.

Combined together with the log message formatting, they already make
it worth an updated patch.

>> diff --git a/t/t0205-gettext-poison.sh b/t/t0205-gettext-poison.sh
>> index f9fa16ad8363..b66d34c6f2bc 100755
>> --- a/t/t0205-gettext-poison.sh
>> +++ b/t/t0205-gettext-poison.sh
>> @@ -33,7 +33,7 @@ test_expect_success 'eval_gettext: our eval_gettext() fallback has poison semant
>>  
>>  test_expect_success "gettext: invalid GIT_TEST_GETTEXT_POISON value doesn't infinitely loop" "
>>  	test_must_fail env GIT_TEST_GETTEXT_POISON=xyz git version 2>error &&
>> -	grep \"fatal: bad numeric config value 'xyz' for 'GIT_TEST_GETTEXT_POISON': invalid unit\" error
>> +	grep \"fatal: bad boolean config value 'xyz' for 'GIT_TEST_GETTEXT_POISON'\" error
>>  "
>
> Do we want a separate test in t1300 that doesn't rely on GETTEXT_POISON
> continuing to hang around (the idea has been thrown around elsewhere of
> it maybe going away entirely)?

Yeah, I do not think it is a good idea to add more test that depends
on GETTEXT_POISON and assumes how it works.

We certainly wish that we want to ensure more quality translation
and more complete i18n coverage, but the "pretend as if the test
passed if it tries to judge the success/failure by looking at the
output string from the command that can be translated, to ferret out
mistakenly marked machine readable string for translation", which is
what the current GETTEXT_POISON thing is, does not contribute much
to improving translation.

@KlotzAndrew KlotzAndrew force-pushed the better_bool_errors branch 3 times, most recently from efc4492 to 33e0e2a Compare February 10, 2021 04:10
Currently invalid boolean config values return messages about 'bad
numeric', which is slightly misleading when the error was due to a
boolean value. We can improve the developer experience by returning a
boolean error message when we know the value is neither a bool text or
int.

before with an invalid boolean value of `non-boolean`, its unclear what
numeric is referring to:
  fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit

now the error message mentions `non-boolean` is a bad boolean value:
  fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'

Signed-off-by: Andrew Klotz <agc.klotz@gmail.com>
@KlotzAndrew
Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git
Copy link
Copy Markdown

Submitted as pull.841.v3.git.git.1613075454274.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git pr-git-841/KlotzAndrew/better_bool_errors-v3

To fetch this version to local tag pr-git-841/KlotzAndrew/better_bool_errors-v3:

git fetch --no-tags https://github.com/gitgitgadget/git tag pr-git-841/KlotzAndrew/better_bool_errors-v3

@gitgitgadget-git
Copy link
Copy Markdown

This branch is now known as ak/config-bad-bool-error.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via 72199fd.

@gitgitgadget-git
Copy link
Copy Markdown

On the Git mailing list, Jeff King wrote (reply to this):

On Thu, Feb 11, 2021 at 08:30:53PM +0000, Andrew Klotz via GitGitGadget wrote:

> From: Andrew Klotz <agc.klotz@gmail.com>
> 
> Currently invalid boolean config values return messages about 'bad
> numeric', which is slightly misleading when the error was due to a
> boolean value. We can improve the developer experience by returning a
> boolean error message when we know the value is neither a bool text or
> int.
> 
> before with an invalid boolean value of `non-boolean`, its unclear what
> numeric is referring to:
>   fatal: bad numeric config value 'non-boolean' for 'commit.gpgsign': invalid unit
> 
> now the error message mentions `non-boolean` is a bad boolean value:
>   fatal: bad boolean config value 'non-boolean' for 'commit.gpgsign'
> 
> Signed-off-by: Andrew Klotz <agc.klotz@gmail.com>

Thanks, all the changes here look good to me except for one curiosity:

> diff --git a/config.c b/config.c
> index b922b4f28572..f90b633dba21 100644
> --- a/config.c
> +++ b/config.c
> @@ -1180,6 +1180,20 @@ static void die_bad_number(const char *name, const char *value)
>  	}
>  }
>  
> +NORETURN
> +static void die_bad_bool(const char *name, const char *value)
> +{
> +	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
> +		/*
> +		 * We explicitly *don't* use _() here since it would
> +		 * cause an infinite loop with _() needing to call
> +		 * use_gettext_poison().
> +		 */
> +		die("bad boolean config value '%s' for '%s'", value, name);
> +	else
> +		die(_("bad boolean config value '%s' for '%s'"), value, name);
> +}

...if this is rebased on the current master that does not have
GIT_TEST_GETTEXT_POISON anymore, then I think this whole function can be
simplified down to the final line.

Since it looks like Junio applied this on top of v2.30.1, which still
has GETTEXT_POISON, we need it here. But we should remember to remove it
with the rest of the GETTEXT_POISON once it's all merged together.

-Peff

@gitgitgadget-git
Copy link
Copy Markdown

On the Git mailing list, Junio C Hamano wrote (reply to this):

Jeff King <peff@peff.net> writes:

> Thanks, all the changes here look good to me except for one curiosity:
>
>> diff --git a/config.c b/config.c
>> index b922b4f28572..f90b633dba21 100644
>> --- a/config.c
>> +++ b/config.c
>> @@ -1180,6 +1180,20 @@ static void die_bad_number(const char *name, const char *value)
>>  	}
>>  }
>>  
>> +NORETURN
>> +static void die_bad_bool(const char *name, const char *value)
>> +{
>> +	if (!strcmp(name, "GIT_TEST_GETTEXT_POISON"))
>> +		/*
>> +		 * We explicitly *don't* use _() here since it would
>> +		 * cause an infinite loop with _() needing to call
>> +		 * use_gettext_poison().
>> +		 */
>> +		die("bad boolean config value '%s' for '%s'", value, name);
>> +	else
>> +		die(_("bad boolean config value '%s' for '%s'"), value, name);
>> +}
>
> ...if this is rebased on the current master that does not have
> GIT_TEST_GETTEXT_POISON anymore, then I think this whole function can be
> simplified down to the final line.
>
> Since it looks like Junio applied this on top of v2.30.1, which still
> has GETTEXT_POISON, we need it here. But we should remember to remove it
> with the rest of the GETTEXT_POISON once it's all merged together.

Thanks for being extra careful.  I sort-of considered that this was
a bugfix and that was why it is made mergeable down to the maint
track, but I do not mind making this one of the "incentives" to
upgrade for our users ;-)

I actually suspect that without any of us worrying about it, Ævar
will take care of the cleaning up when the dust settles.

Thanks.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via 1ff8637.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into next via 76784be.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into seen via 483e09e.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into next via 483e09e.

@gitgitgadget-git
Copy link
Copy Markdown

This patch series was integrated into master via 483e09e.

@gitgitgadget-git
Copy link
Copy Markdown

Closed via 483e09e.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants