Subject: | wierd error reporting when run without controlling terminal |
Hello,
I'm using the module in http://search.cpan.org/dist/Quietly-Confident/
and it works very well. However, I observed some strange behavior. The
script I'm using works on a git repository but it is also able to do
fallback on simple filesystem operations. For this to work, I catch
errors returned by Git::Repository using eval{}:
sub watch {
my ($git) = @_;
my $gitmode = 1;
if(! $git) {
eval {
$git = Git::Repository->new( work_tree => $config{repository} )
or die "Could not init git: $!\n";
};
if($@ || ! -d "$config{repository}/.git") {
print STDERR "$config{repository} is not a git repository!\n";
print STDERR "Watching in filesystem mode.\n";
$gitmode = 0;
}
}
if($gitmode) {
&log("gitwatch");
&gitwatch($git);
}
else {
&log("fswatch");
&fswatch();
}
}
This routine works as expected when run in a controlling terminal
session. But the script is also able to run as a daemon using fork() and
this is what happens then:
- if STDERR is closed (what I usually do when in daemon mode),
Git::Repository causes the script to terminate.
- if I leave STDERR open, it prints the following message to STDERR:
fatal: Not a git repository (or any parent up to mount parent /home)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not
set). at /usr/local/lib/perl5/site_perl/5.10.1/Git/Repository.pm line 195
but keeps running.
This is the very same message I'm catching in the eval{} block above
(and ignoring it to go to the fallback mode). And as extra bonus the
eval{} block doesn't catch the error in daemon mode. $@ is empty and
instead Git::Repository prints it itself to STDERR, if available, or
exits if not.
I'm not sure wether this is caused by Git::Repository itself or by
behavior of the underlying git command. But it would be great if I could
catch errors using eval{} as expected when not connected to a
controlling terminal session.
best regards,
Tom