# [PATCH] Use exit 1 instead of die when req_Root fails.

12 messages from 2007-10-17 to 2007-10-18. Participants: Brian Gernhardt, Morten Welinder, Lars Hjemli, Frank Lichtenheld, Shawn O. Pearce, Jan Hudec.
Thread: https://gitlist.dev/t/10343

## Brian Gernhardt, 2007-10-17 14:05

Subject: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071017140547.GA21691@Hermes.cust.hotspot.t-mobile.com>
URL: https://gitlist.dev/e/20071017140547.GA21691%40Hermes.cust.hotspot.t-mobile.com

```
This was causing test failures because die was exiting 255.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
---

 Shawn, I sent this in a couple weeks ago but it looks like it never
 made it into your repo.  It fixes test failures on my machine that have
 been plauging me for months.

 git-cvsserver.perl |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/git-cvsserver.perl b/git-cvsserver.perl
index 13dbd27..0d55fec 100755
--- a/git-cvsserver.perl
+++ b/git-cvsserver.perl
@@ -145,8 +145,10 @@ if ($state->{method} eq 'pserver') {
     }
     my $request = $1;
     $line = <STDIN>; chomp $line;
-    req_Root('root', $line) # reuse Root
-       or die "E Invalid root $line \n";
+    unless (req_Root('root', $line)) { # reuse Root
+       print "E Invalid root $line \n";
+       exit 1;
+    }
     $line = <STDIN>; chomp $line;
     unless ($line eq 'anonymous') {
        print "E Only anonymous user allowed via pserver\n";
-- 
1.5.3.4.206.g0cef9

```

## Morten Welinder, 2007-10-17 14:39

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <118833cc0710170739i179e7389k1e44f70086ca88be@mail.gmail.com>
URL: https://gitlist.dev/e/118833cc0710170739i179e7389k1e44f70086ca88be%40mail.gmail.com
In-Reply-To: <20071017140547.GA21691@Hermes.cust.hotspot.t-mobile.com>

```
>  made it into your repo.  It fixes test failures on my machine that have
>  been plauging me for months.

That sounds more like a reason to fix the test.  "die" is the perl
standard way of
reporting an error.  It will print the error message on stderr, not on
stdout like
your version does.

IMHO, of course.

Morten

```

## Brian Gernhardt, 2007-10-17 15:16

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <DC3D43FD-F03D-4E0A-9C2B-DE56F9C16D60@silverinsanity.com>
URL: https://gitlist.dev/e/DC3D43FD-F03D-4E0A-9C2B-DE56F9C16D60%40silverinsanity.com
In-Reply-To: <118833cc0710170739i179e7389k1e44f70086ca88be@mail.gmail.com>

```

On Oct 17, 2007, at 10:39 AM, Morten Welinder wrote:

>>  made it into your repo.  It fixes test failures on my machine  
>> that have
>>  been plauging me for months.
>
> That sounds more like a reason to fix the test.  "die" is the perl
> standard way of reporting an error.  It will print the error message
> on stderr, not on stdout like your version does.
>
> IMHO, of course.

The problem is that die can exit with varying exit codes, and exit  
codes >= 128 make the test suite assume something has gone wrong with  
the test.  In particular, because $! (errcode) and $? (previous shell  
command return) are both 0, it returns 255.  Or at least that's how  
it works out on my system.  I'm not sure why it doesn't do that on  
others.

But the test is expecting a failure here and it appears to be failing  
in the correct way, just with an error code test-lib.sh doesn't  
like.  I asked on list the best way to fix it and Frank Lichtenheld  
said (and nobody objected until now) that this was the best way to  
fix it.

Also, the not printing on STRERR is identical to another section of  
code just below mine:

>     unless ($line eq 'anonymous') {
>        print "E Only anonymous user allowed via pserver\n";
>        print "I HATE YOU\n";
>        exit 1;
>     }

However, amending my patch to print to STDERR is not difficult.

~~ Brian Gernhardt

```

## Lars Hjemli, 2007-10-17 15:39

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <8c5c35580710170839l4b31a4fao5b41efafc5a83883@mail.gmail.com>
URL: https://gitlist.dev/e/8c5c35580710170839l4b31a4fao5b41efafc5a83883%40mail.gmail.com
In-Reply-To: <DC3D43FD-F03D-4E0A-9C2B-DE56F9C16D60@silverinsanity.com>

```
On 10/17/07, Brian Gernhardt <benji@silverinsanity.com> wrote:
> The problem is that die can exit with varying exit codes, and exit
> codes >= 128 make the test suite assume something has gone wrong with
> the test.

This makes me wonder: what about all the other instances of die() in
git-cvsserver? Or in any of the other perl scripts, for that matter?
Should they all be fixed, or is it this particular test that is wrong?

-- 
larsh

```

## Brian Gernhardt, 2007-10-17 18:40

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <8B2F7666-DCEB-4D58-ACFE-F40587CD415D@silverinsanity.com>
URL: https://gitlist.dev/e/8B2F7666-DCEB-4D58-ACFE-F40587CD415D%40silverinsanity.com
In-Reply-To: <8c5c35580710170839l4b31a4fao5b41efafc5a83883@mail.gmail.com>

```
I wish I got this much attention the first time I tried to get this  
problem fixed.  ;-)

On Oct 17, 2007, at 11:39 AM, Lars Hjemli wrote:

> This makes me wonder: what about all the other instances of die() in
> git-cvsserver? Or in any of the other perl scripts, for that matter?
> Should they all be fixed, or is it this particular test that is wrong?

The reason this comes up is because t/test-lib.sh:test_expect_failure 
() thinks codes > 128 (or negative values if you want to look at it  
that way) are bad tests.  I believe this is because many shells use  
these codes to indicate things like "command not found" or other  
probably unexpected failures.

Other than that, does it matter what die() returns, as long as it's  
non-zero?

~~Brian

```

## Frank Lichtenheld, 2007-10-17 19:06

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071017190646.GC9041@planck.djpig.de>
URL: https://gitlist.dev/e/20071017190646.GC9041%40planck.djpig.de
In-Reply-To: <20071017140547.GA21691@Hermes.cust.hotspot.t-mobile.com>

```
On Wed, Oct 17, 2007 at 10:05:47AM -0400, Brian Gernhardt wrote:
> This was causing test failures because die was exiting 255.
> 
> Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
> ---
> 
>  Shawn, I sent this in a couple weeks ago but it looks like it never
>  made it into your repo.  It fixes test failures on my machine that have
>  been plauging me for months.

I have this in my repo and will submit this with the other git-cvsserver
changes. I was just waiting for either Junio to return or someone else
stepping up.

Gruesse,
-- 
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/

```

## Frank Lichtenheld, 2007-10-17 19:08

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071017190822.GD9041@planck.djpig.de>
URL: https://gitlist.dev/e/20071017190822.GD9041%40planck.djpig.de
In-Reply-To: <118833cc0710170739i179e7389k1e44f70086ca88be@mail.gmail.com>

```
On Wed, Oct 17, 2007 at 10:39:52AM -0400, Morten Welinder wrote:
> >  made it into your repo.  It fixes test failures on my machine that have
> >  been plauging me for months.
> 
> That sounds more like a reason to fix the test.  "die" is the perl
> standard way of
> reporting an error.  It will print the error message on stderr, not on
> stdout like
> your version does.

Please note that git-cvsserver is special in that its output will never
be displayed directly to the user but is always interpreted first by
the client. So print "E something" is acutally in some cases more
correct than print STDERR something.

Gruesse,
-- 
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/

```

## Brian Gernhardt, 2007-10-17 19:15

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <98FA3712-B4E5-499A-B3E5-818FC33833DA@silverinsanity.com>
URL: https://gitlist.dev/e/98FA3712-B4E5-499A-B3E5-818FC33833DA%40silverinsanity.com
In-Reply-To: <20071017190646.GC9041@planck.djpig.de>

```

On Oct 17, 2007, at 3:06 PM, Frank Lichtenheld wrote:

> I have this in my repo and will submit this with the other git- 
> cvsserver
> changes. I was just waiting for either Junio to return or someone else
> stepping up.

Ah.  I had missed that.  I just dug up the patch when switching to  
Shawn's repo gave me those old testing errors.  Had thought it had  
gotten lost in the shuffle.

Never mind me then,
~~ Brian

```

## Lars Hjemli, 2007-10-17 19:27

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <8c5c35580710171227o45c6b113ve10f293a4505bab5@mail.gmail.com>
URL: https://gitlist.dev/e/8c5c35580710171227o45c6b113ve10f293a4505bab5%40mail.gmail.com
In-Reply-To: <8B2F7666-DCEB-4D58-ACFE-F40587CD415D@silverinsanity.com>

```
On 10/17/07, Brian Gernhardt <benji@silverinsanity.com> wrote:
> I wish I got this much attention the first time I tried to get this
> problem fixed.  ;-)
>
> On Oct 17, 2007, at 11:39 AM, Lars Hjemli wrote:
>
> > This makes me wonder: what about all the other instances of die() in
> > git-cvsserver? Or in any of the other perl scripts, for that matter?
> > Should they all be fixed, or is it this particular test that is wrong?
>
> The reason this comes up is because t/test-lib.sh:test_expect_failure
> () thinks codes > 128 (or negative values if you want to look at it
> that way) are bad tests.  I believe this is because many shells use
> these codes to indicate things like "command not found" or other
> probably unexpected failures.
>
> Other than that, does it matter what die() returns, as long as it's
> non-zero?

My point exactly ;-)

If the test is changed to use 'test_expect_success' in the same way as
'req_Root failure (relative pathname)' does it, the test no longer
depends on the exact exit-code returned by die().

IMHO this is much better future-proofing than replacing die() with
print()/exit 1 whenever one of these tests fails.

--
larsh

```

## Shawn O. Pearce, 2007-10-18 05:04

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071018050456.GD14735@spearce.org>
URL: https://gitlist.dev/e/20071018050456.GD14735%40spearce.org
In-Reply-To: <98FA3712-B4E5-499A-B3E5-818FC33833DA@silverinsanity.com>

```
Brian Gernhardt <benji@silverinsanity.com> wrote:
> On Oct 17, 2007, at 3:06 PM, Frank Lichtenheld wrote:
> 
> >I have this in my repo and will submit this with the other git- 
> >cvsserver
> >changes. I was just waiting for either Junio to return or someone else
> >stepping up.
> 
> Ah.  I had missed that.  I just dug up the patch when switching to  
> Shawn's repo gave me those old testing errors.  Had thought it had  
> gotten lost in the shuffle.

It did.  I have your resubmit that started this thread in my INQ and
will try to get to it today.  But if Frank has a queue of stuff I've
missed I'd like a pointer to it so I can also try to start working
through it.  I know I also have some other topics that Lars Hjemli
accumlated in his tree that I still need to cherry-pick over into
mine, but I don't see the one we are talking about in there.

-- 
Shawn.

```

## Frank Lichtenheld, 2007-10-18 13:33

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071018133322.GC3917@planck.djpig.de>
URL: https://gitlist.dev/e/20071018133322.GC3917%40planck.djpig.de
In-Reply-To: <20071018050456.GD14735@spearce.org>

```
On Thu, Oct 18, 2007 at 01:04:56AM -0400, Shawn O. Pearce wrote:
> Brian Gernhardt <benji@silverinsanity.com> wrote:
> > On Oct 17, 2007, at 3:06 PM, Frank Lichtenheld wrote:
> > 
> > >I have this in my repo and will submit this with the other git- 
> > >cvsserver
> > >changes. I was just waiting for either Junio to return or someone else
> > >stepping up.
> > 
> > Ah.  I had missed that.  I just dug up the patch when switching to  
> > Shawn's repo gave me those old testing errors.  Had thought it had  
> > gotten lost in the shuffle.
> 
> It did.  I have your resubmit that started this thread in my INQ and
> will try to get to it today.  But if Frank has a queue of stuff I've
> missed I'd like a pointer to it so I can also try to start working
> through it.  I know I also have some other topics that Lars Hjemli
> accumlated in his tree that I still need to cherry-pick over into
> mine, but I don't see the one we are talking about in there.

Yeah, I postponed sending it to tomorrow for some days now :/

Anyway, my current queue is visible at
git://source.djpig.de/git/git-cvsserver.git cvsserver
So you can fetch and merge/cherry-pick it yourself if you prefer.

Gruesse,
-- 
Frank Lichtenheld <frank@lichtenheld.de>
www: http://www.djpig.de/

```

## Jan Hudec, 2007-10-18 18:54

Subject: Re: [PATCH] Use exit 1 instead of die when req_Root fails.
Message-ID: <20071018185414.GL26127@efreet.light.src>
URL: https://gitlist.dev/e/20071018185414.GL26127%40efreet.light.src
In-Reply-To: <DC3D43FD-F03D-4E0A-9C2B-DE56F9C16D60@silverinsanity.com>

```
On Wed, Oct 17, 2007 at 11:16:34 -0400, Brian Gernhardt wrote:
>
> On Oct 17, 2007, at 10:39 AM, Morten Welinder wrote:
>
>>>  made it into your repo.  It fixes test failures on my machine that have
>>>  been plauging me for months.
>>
>> That sounds more like a reason to fix the test.  "die" is the perl
>> standard way of reporting an error.  It will print the error message
>> on stderr, not on stdout like your version does.
>>
>> IMHO, of course.
>
> The problem is that die can exit with varying exit codes, and exit codes >= 
> 128 make the test suite assume something has gone wrong with the test.  In 
> particular, because $! (errcode) and $? (previous shell command return) are 
> both 0, it returns 255.  Or at least that's how it works out on my system.  
> I'm not sure why it doesn't do that on others.
>
> But the test is expecting a failure here and it appears to be failing in 
> the correct way, just with an error code test-lib.sh doesn't like.  I asked 
> on list the best way to fix it and Frank Lichtenheld said (and nobody 
> objected until now) that this was the best way to fix it.
>
> Also, the not printing on STRERR is identical to another section of code 
> just below mine:
>
>>     unless ($line eq 'anonymous') {
>>        print "E Only anonymous user allowed via pserver\n";
>>        print "I HATE YOU\n";
>>        exit 1;
>>     }
>
> However, amending my patch to print to STDERR is not difficult.

Hm. There are two kinds of errors in git-cvsserver and they should be handled
differently.

If the error is an invalid request (like the quoted one), there should be
normal print, to STDOUT, starting with "E", because it's an error message
that should be sent to the client.

On the other hand if the error is internal error in the script or it's
configuration, than the error should probably be reported via die, *without*
E at the begining (it will be prefixed with location anyway). Such message
will probably end up in the log rather than sent to the client.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

```
