# git config error message

9 messages from 2012-10-27 to 2012-10-27. Participants: Angelo Borsotti, Andreas Schwab, Ben Walton.
Thread: https://gitlist.dev/t/31955

## Angelo Borsotti, 2012-10-27 08:10

Subject: git config error message
Message-ID: <CAB9Jk9AQkSiv=F8NeYs+uspR5f4CeJS5L-hwZUXdq7dts1W5ng@mail.gmail.com>
URL: https://gitlist.dev/e/CAB9Jk9AQkSiv%3DF8NeYs%2BuspR5f4CeJS5L-hwZUXdq7dts1W5ng%40mail.gmail.com

```
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, 2012-10-27 08:25

Subject: Re: git config error message
Message-ID: <m2bofo9v93.fsf@linux-m68k.org>
URL: https://gitlist.dev/e/m2bofo9v93.fsf%40linux-m68k.org
In-Reply-To: <CAB9Jk9AQkSiv=F8NeYs+uspR5f4CeJS5L-hwZUXdq7dts1W5ng@mail.gmail.com>

```
Angelo Borsotti <angelo.borsotti@gmail.com> writes:

> 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."

```

## Angelo Borsotti, 2012-10-27 08:32

Subject: Re: git config error message
Message-ID: <CAB9Jk9CONVSZvBUgnZHiniwPHHvcap8Wyjyw-sCHaSokDoNRWA@mail.gmail.com>
URL: https://gitlist.dev/e/CAB9Jk9CONVSZvBUgnZHiniwPHHvcap8Wyjyw-sCHaSokDoNRWA%40mail.gmail.com
In-Reply-To: <m2bofo9v93.fsf@linux-m68k.org>

```
Hi Andreas,

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.

-Angelo

```

## Andreas Schwab, 2012-10-27 08:44

Subject: Re: git config error message
Message-ID: <m27gqc9udc.fsf@linux-m68k.org>
URL: https://gitlist.dev/e/m27gqc9udc.fsf%40linux-m68k.org
In-Reply-To: <CAB9Jk9CONVSZvBUgnZHiniwPHHvcap8Wyjyw-sCHaSokDoNRWA@mail.gmail.com>

```
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, 2012-10-27 08:45

Subject: Re: git config error message
Message-ID: <CAP30j15pUwX9sD3FXAfroxFK9paHmb1eAg+M5YAHT4aB22DBEw@mail.gmail.com>
URL: https://gitlist.dev/e/CAP30j15pUwX9sD3FXAfroxFK9paHmb1eAg%2BM5YAHT4aB22DBEw%40mail.gmail.com
In-Reply-To: <CAB9Jk9CONVSZvBUgnZHiniwPHHvcap8Wyjyw-sCHaSokDoNRWA@mail.gmail.com>

```
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, 2012-10-27 10:36

Subject: Re: git config error message
Message-ID: <CAB9Jk9COSZOske5xzgnE=1oHe7qiwwOzHYE6pJkuZ0sZyZYhng@mail.gmail.com>
URL: https://gitlist.dev/e/CAB9Jk9COSZOske5xzgnE%3D1oHe7qiwwOzHYE6pJkuZ0sZyZYhng%40mail.gmail.com
In-Reply-To: <CAP30j15pUwX9sD3FXAfroxFK9paHmb1eAg+M5YAHT4aB22DBEw@mail.gmail.com>

```
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.

> 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, 2012-10-27 13:14

Subject: Re: git config error message
Message-ID: <m2d3049hvs.fsf@igel.home>
URL: https://gitlist.dev/e/m2d3049hvs.fsf%40igel.home
In-Reply-To: <CAB9Jk9COSZOske5xzgnE=1oHe7qiwwOzHYE6pJkuZ0sZyZYhng@mail.gmail.com>

```
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, 2012-10-27 14:50

Subject: Re: git config error message
Message-ID: <CAB9Jk9A-uXXXKCBKvxyDN6QQx1b0zqemg7UbeRMcWeY7gi4MRQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAB9Jk9A-uXXXKCBKvxyDN6QQx1b0zqemg7UbeRMcWeY7gi4MRQ%40mail.gmail.com
In-Reply-To: <m2d3049hvs.fsf@igel.home>

```
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

>> 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, 2012-10-27 16:12

Subject: Re: git config error message
Message-ID: <m2r4oj99mq.fsf@igel.home>
URL: https://gitlist.dev/e/m2r4oj99mq.fsf%40igel.home
In-Reply-To: <CAB9Jk9A-uXXXKCBKvxyDN6QQx1b0zqemg7UbeRMcWeY7gi4MRQ@mail.gmail.com>

```
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."

```
