[darcs-devel] [issue858] Darcs doesn't return a proper exit code on errors

gwern bugs at darcs.net
Fri May 16 18:01:16 UTC 2008


New submission from gwern <gwern0 at gmail.com>:

So I recently was trying to download the announced ChessLibrary library from
http://code.haskell.org/ChessLibrary . Alas, each and every Darcs get failed. I
verified I could access it at all by visiting it in a browser, but the gets kept
failing.

How irksome! Perhaps there was some transient network problem that would go away
with sufficient brute force. So I did a basic shell script:

 while true; do get http://code.haskell.org/ChessLibrary/ && break; done

(The idea is, if Darcs ever succeeds, we break out of the infinite loop.)

Imagine my surprise when the loop ran exactly once, but I had no useable
ChessLibrary directory.

Why? Well:

gwern at localhost:5238~/bin/darcs/darcs.net>darcs get
http://code.haskell.org/ChessLibrary/ && echo foo                              
[ 1:58PM]
Directory '/home/gwern/bin/darcs/darcs.net/ChessLibrary' already exists,
creating repository as '/home/gwern/bin/darcs/darcs.net/ChessLibrary_1'

darcs failed:  Not a repository: http://code.haskell.org/ChessLibrary (Failed to
download URL http://code.haskell.org/ChessLibrary/_darcs/inventory: HTTP
response code said error)
foo


So in other words, Darcs was claiming success even in the face of utter failure.
Much as I admire such indomitable willpower and optimism, it gets in the way. :)

I went code hunting, and I found that withSignalsHandled was doing the right
thing, it was setting an ExitStatus of Failure. So Darcs should've been exiting
the right way. But it seems that in darcs.lhs, withSignalsHandled is passed on
to with_atexit in Global.hs. And with_atexit throws away the information: it
returns successfully - after doing some printing to stderr.

I edited it lightly to guarantee an erroneous exit status:

gwern at localhost:5239~/bin/darcs/darcs.net>new                                  
                                                    [ 1:58PM]
hunk ./src/Darcs/Global.lhs 70               
-            hPutStrLn stderr $ "Exception thrown by an atexit registered action:"
-            hPutStrLn stderr $ show exn
+           hPutStrLn stderr $ "Exception thrown by an atexit registered action:"
+           error $ show exn

And I tried with those changes:

gwern at localhost:5236~/bin/darcs/darcs.net>./darcs get
http://code.haskell.org/ChessLibrary/ && echo foo                             [
2:04PM]
Directory '/home/gwern/bin/darcs/darcs.net/ChessLibrary' already exists,
creating repository as '/home/gwern/bin/darcs/darcs.net/ChessLibrary_2'
                                                                     
darcs failed:  Not a repository: http://code.haskell.org/ChessLibrary (Failed to
download URL http://code.haskell.org/ChessLibrary/_darcs/inventory: HTTP
response code said error)

Much better.

Oddly, this seems to cause test problems (otherwise I'd record and send):

TESTS FAILED!
	whatsnew.sh
	either_dependency.sh

Do these tests depend on Darcs always succeeding, or were some regressions
introduced when I wasn't looking?

----------
messages: 4726
nosy: beschmi, dagit, gwern, tommy
priority: bug
status: unread
title: Darcs doesn't return a proper exit code on errors

__________________________________
Darcs bug tracker <bugs at darcs.net>
<http://bugs.darcs.net/issue858>
__________________________________


More information about the darcs-devel mailing list