threads / discuss / 31955

git config error message

Subject: git config error message

## tl;dr

9 messages between Oct 27, 2012 and Oct 27, 2012.

replies: 8people: 3as markdown or json

Angelo Borsotti· Oct 27, 2012, 08:10 UTC · lore
Hello,

git config --get issues an error message when the specified value contains a section that does not exist, but does not issue any message when the value contains a key that does not exist while in both cases returning a status 1. E.g.

$ git config --get xxx error: key does not contain a section: xxx

$ git config --get xxx.yyy
Proposal: to issue an error message also when the key does not exist.
-Angelo Borsotti
Andreas Schwab· Oct 27, 2012, 08:25 UTC · re: Angelo Borsotti · lore

Re: git config error message

Angelo Borsotti <angelo.borsotti@gmail.com> writes:
Show 11 quoted lines
> git config --get issues an error message when the specified value
> contains a section that does not exist, but does not issue any message
> when the value contains a key that does not exist while in both cases
> returning a status 1. E.g.
>
> $ git config --get xxx
> error: key does not contain a section: xxx
>
> $ git config --get xxx.yyy
>
> Proposal: to issue an error message also when the key does not exist.

The two cases are different: a key without a section is malformed, whereas a nonexistent value is usually not an error (use the default instead).

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Andreas Schwab· Oct 27, 2012, 08:44 UTC · re: Angelo Borsotti · lore

Re: git config error message

Angelo Borsotti <angelo.borsotti@gmail.com> writes:
> I wrote "value", but I meant "name". The first example I made contains
> a name with a nonexistent section, the second a name with a
> nonexistent key.
And a nonexistent key is a valid key, so not an error.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Ben Walton· Oct 27, 2012, 08:45 UTC · re: Angelo Borsotti · lore

Re: git config error message

On Sat, Oct 27, 2012 at 9:32 AM, Angelo Borsotti <angelo.borsotti@gmail.com> wrote:

Hi Angelo,
> I wrote "value", but I meant "name". The first example I made contains
> a name with a nonexistent section, the second a name with a
> nonexistent key.

This still wouldn't be an error condition though, especially in terms of how "git config" should treat it. It should be up to the consumer of the information to display, or not, any error or diagnostics that don't result from either a bad request (your first case) or a malformed configuration file. This fits with the callback nature of how the config file is parsed by builtin tools. The exit code from "git config" with a missing key is enough for the consumer to make this decision.

This is just my take on it, but I think the current approach makes sense.

Thanks -Ben

-- 
---------------------------------------------------------------------------------------------------------------------------
Take the risk of thinking for yourself.  Much more happiness,
truth, beauty and wisdom will come to you that way.

-Christopher Hitchens
---------------------------------------------------------------------------------------------------------------------------
Angelo Borsotti· Oct 27, 2012, 10:36 UTC · re: Ben Walton · lore

Re: git config error message

Hi Ben
> This still wouldn't be an error condition though, especially in terms
> of how "git config" should treat it.
The man page says:
   "This command will fail with non-zero status upon error."

Of course, one might claim that this does not mean the truth of the reverse condition, i.e. that when the command returns 1 that is necessarily an error, but I would leave that avenue of thinking to philosophers. Besides that, it is common practice in *nix OSs to consider a return != 0 as an error.

Show 8 quoted lines
> It should be up to the consumer
> of the information to display, or not, any error or diagnostics that
> don't result from either a bad request (your first case) or a
> malformed configuration file.  This fits with the callback nature of
> how the config file is parsed by builtin tools.  The exit code from
> "git config" with a missing key is enough for the consumer to make
> this decision.
>

A well-behaved, user-friendly program, when detects an error tells the user what went wrong. How can otherwise the user tell a corrupted configuration file from a missing key?

Of course, is is possible to provide a git-config that simply returns 0 when it has got the key and 1 when it does not, without issuing any error message, but the current one is not like that, it is a middle way solution.

-Angelo
Andreas Schwab· Oct 27, 2012, 13:14 UTC · re: Angelo Borsotti · lore

Re: git config error message

Angelo Borsotti <angelo.borsotti@gmail.com> writes:
> Besides that, it is common practice in *nix OSs to
> consider a return != 0 as an error.

Is grep not finding a match an error? Is cmp finding a difference an error? It all depends on the context.

> How can otherwise the user tell a corrupted configuration file from a
> missing key?

You cannot, as long as your configuration file is well-formed, because a missing key is an expected condition in many cases.

Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Angelo Borsotti· Oct 27, 2012, 14:50 UTC · re: Andreas Schwab · lore

Re: git config error message

Hi Andreas,
>
> Is grep not finding a match an error?  Is cmp finding a difference an
> error?  It all depends on the context.
>
Manpage of grep, exit staus:
   "Normally, the exit status is 0 if selected lines are found and 1
otherwise. But the exit status is 2 if an error occurred, ..."
cmp uses the same convention (albeit not reported in its manpage).

I am not stating that all linux commands and utilities follow exactly the same convention, but these two are at least consistent with themselves always returning an exit status that has a well defined meaning. git-config returns consistently the exit status, it only issues in certain cases messages and in others not. A consistent solution could be for it to return 0 upon success, 1 when the section or key is absent, and 2 when the config file does not exist or is corrupt issuing also an error message.

-Angelo
Show 12 quoted lines
>> How can otherwise the user tell a corrupted configuration file from a
>> missing key?
>
> You cannot, as long as your configuration file is well-formed, because a
> missing key is an expected condition in many cases.
>
> Andreas.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
Andreas Schwab· Oct 27, 2012, 16:12 UTC · re: Angelo Borsotti · lore

Re: git config error message

Angelo Borsotti <angelo.borsotti@gmail.com> writes:
> when the section or key is absent
When the key is malformed you get an error, otherwise not.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

← back to recent threads