Re: [PATCH] Git.pm: better error message
On Mon, Jun 14, 2010 at 03:10:46AM -0400, Jeff King wrote:
Show 17 quoted lines
> On Mon, Jun 14, 2010 at 03:00:22AM +0200, Philippe Bruhat (BooK) wrote:
>
> > -d doesn't set $! if the directory doesn't exist
>
> Really?
>
> $ perl -e '-d "bogus" or die "fail: $!"'
> fail: No such file or directory at -e line 1.
>
> On the other hand:
>
> $ touch file
> perl -e '-d "file" or die "fail: $!"'
> fail: at -e line 1.
>
> So perhaps it is best not to rely on $!. Also, this is with perl 5.10.
> Is it different with other versions?
Come to think of it, it probably makes sense: -d probably depends on stat to get the information about the file, and that fails harder when the file in question doesn't exists.
I guess the best would be to put the directory name in the error message (always interesting information), and keep $! in case it was set by an harder error.
--
Philippe Bruhat (BooK)
There is no solution to a problem of sheer greed.
(Moral from Groo The Wanderer #94 (Epic))