From: Subho Sankar Banerjee <subs.zero@gmail.com>
To: git@vger.kernel.org
Cc: Subho Sankar Banerjee <subs.zero@gmail.com>
Subject: [PATCH][GIT.PM 2/3] Getting rid of throwing Error::Simple objects in favour of simple Perl scalars which can be caught in eval{} blocks
Date: Sat, 19 May 2012 12:38:36 +0530 [thread overview]
Message-ID: <1337411317-14931-2-git-send-email-subs.zero@gmail.com> (raw)
In-Reply-To: <1337411317-14931-1-git-send-email-subs.zero@gmail.com>
Signed-off-by: Subho Sankar Banerjee <subs.zero@gmail.com>
---
perl/Git.pm | 52 ++++++++++++++++++++++++++--------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/perl/Git.pm b/perl/Git.pm
index 497f420..52777d4 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -160,7 +160,7 @@ sub repository {
if (defined $args[0]) {
if ($#args % 2 != 1) {
# Not a hash.
- $#args == 0 or throw Error::Simple("bad usage");
+ $#args == 0 or die "bad usage";
%opts = ( Directory => $args[0] );
} else {
%opts = @args;
@@ -173,7 +173,7 @@ sub repository {
}
if (defined $opts{Directory}) {
- -d $opts{Directory} or throw Error::Simple("Directory not found: $opts{Directory} $!");
+ -d $opts{Directory} or die "Directory not found: $opts{Directory} $!";
my $search = Git->repository(WorkingCopy => $opts{Directory});
my $dir;
@@ -193,7 +193,7 @@ sub repository {
$dir = abs_path($opts{Directory}) . '/';
if ($prefix) {
if (substr($dir, -length($prefix)) ne $prefix) {
- throw Error::Simple("rev-parse confused me - $dir does not have trailing $prefix");
+ die "rev-parse confused me - $dir does not have trailing $prefix";
}
substr($dir, -length($prefix)) = '';
}
@@ -206,14 +206,14 @@ sub repository {
unless (-d "$dir/refs" and -d "$dir/objects" and -e "$dir/HEAD") {
# Mimic git-rev-parse --git-dir error message:
- throw Error::Simple("fatal: Not a git repository: $dir");
+ die "fatal: Not a git repository: $dir";
}
my $search = Git->repository(Repository => $dir);
try {
$search->command('symbolic-ref', 'HEAD');
} catch Git::Error::Command with {
# Mimic git-rev-parse --git-dir error message:
- throw Error::Simple("fatal: Not a git repository: $dir");
+ die "fatal: Not a git repository: $dir";
}
$opts{Repository} = abs_path($dir);
@@ -469,7 +469,7 @@ sub command_noisy {
my $pid = fork;
if (not defined $pid) {
- throw Error::Simple("fork failed: $!");
+ die "fork failed: $!";
} elsif ($pid == 0) {
_cmd_exec($self, $cmd, @args);
}
@@ -552,10 +552,10 @@ and the directory must exist.
sub wc_chdir {
my ($self, $subdir) = @_;
$self->wc_path()
- or throw Error::Simple("bare repository");
+ or die "bare repository";
-d $self->wc_path().'/'.$subdir
- or throw Error::Simple("subdir not found: $subdir $!");
+ or die "subdir not found: $subdir $!";
# Of course we will not "hold" the subdirectory so anyone
# can delete it now and we will never know. But at least we tried.
@@ -825,13 +825,13 @@ sub hash_and_insert_object {
unless (print $out $filename, "\n") {
$self->_close_hash_and_insert_object();
- throw Error::Simple("out pipe went bad");
+ die "out pipe went bad";
}
chomp(my $hash = <$in>);
unless (defined($hash)) {
$self->_close_hash_and_insert_object();
- throw Error::Simple("in pipe went bad");
+ die "in pipe went bad";
}
return $hash;
@@ -873,7 +873,7 @@ sub cat_blob {
unless (print $out $sha1, "\n") {
$self->_close_cat_blob();
- throw Error::Simple("out pipe went bad");
+ die "out pipe went bad";
}
my $description = <$in>;
@@ -900,7 +900,7 @@ sub cat_blob {
my $read = read($in, $blob, $bytesToRead, $bytesRead);
unless (defined($read)) {
$self->_close_cat_blob();
- throw Error::Simple("in pipe went bad");
+ die "in pipe went bad";
}
$bytesRead += $read;
@@ -911,16 +911,16 @@ sub cat_blob {
my $read = read($in, $newline, 1);
unless (defined($read)) {
$self->_close_cat_blob();
- throw Error::Simple("in pipe went bad");
+ die "in pipe went bad";
}
unless ($read == 1 && $newline eq "\n") {
$self->_close_cat_blob();
- throw Error::Simple("didn't find newline after blob");
+ die "didn't find newline after blob";
}
unless (print $fh $blob) {
$self->_close_cat_blob();
- throw Error::Simple("couldn't write to passed in filehandle");
+ die "couldn't write to passed in filehandle";
}
return $size;
@@ -1023,8 +1023,8 @@ sub _temp_cache {
my $temp_fd = \$TEMP_FILEMAP{$name};
if (defined $$temp_fd and $$temp_fd->opened) {
if ($TEMP_FILES{$$temp_fd}{locked}) {
- throw Error::Simple("Temp file with moniker '" .
- $name . "' already in use");
+ die "Temp file with moniker '" .
+ $name . "' already in use";
}
} else {
if (defined $$temp_fd) {
@@ -1041,7 +1041,7 @@ sub _temp_cache {
($$temp_fd, $fname) = File::Temp->tempfile(
'Git_XXXXXX', UNLINK => 1, DIR => $tmpdir,
- ) or throw Error::Simple("couldn't open new temp file");
+ ) or die "couldn't open new temp file";
$$temp_fd->autoflush;
binmode $$temp_fd;
@@ -1052,7 +1052,7 @@ sub _temp_cache {
sub _verify_require {
eval { require File::Temp; require File::Spec; };
- $@ and throw Error::Simple($@);
+ $@ and die "$@";
}
=item temp_reset ( FILEHANDLE )
@@ -1065,11 +1065,11 @@ sub temp_reset {
my ($self, $temp_fd) = _maybe_self(@_);
truncate $temp_fd, 0
- or throw Error::Simple("couldn't truncate file");
+ or die "couldn't truncate file";
sysseek($temp_fd, 0, SEEK_SET) and seek($temp_fd, 0, SEEK_SET)
- or throw Error::Simple("couldn't seek to beginning of file");
+ or die "couldn't seek to beginning of file";
sysseek($temp_fd, 0, SEEK_CUR) == 0 and tell($temp_fd) == 0
- or throw Error::Simple("expected file position to be reset");
+ or die "expected file position to be reset";
}
=item temp_path ( NAME )
@@ -1100,8 +1100,8 @@ sub END {
=head1 ERROR HANDLING
All functions are supposed to throw Perl exceptions in case of errors.
-See the L<Error> module on how to catch those. Most exceptions are mere
-L<Error::Simple> instances.
+These errors are perl scalars which can be caught in the $@ values in
+eval{} blocks.
However, the C<command()>, C<command_oneline()> and C<command_noisy()>
functions suite can throw C<Git::Error::Command> exceptions as well: those are
@@ -1227,7 +1227,7 @@ sub _maybe_self {
# Check if the command id is something reasonable.
sub _check_valid_cmd {
my ($cmd) = @_;
- $cmd =~ /^[a-z0-9A-Z_-]+$/ or throw Error::Simple("bad command: $cmd");
+ $cmd =~ /^[a-z0-9A-Z_-]+$/ or die "bad command: $cmd";
}
# Common backend for the pipe creators.
@@ -1261,7 +1261,7 @@ sub _command_common_pipe {
} else {
my $pid = open($fh, $direction);
if (not defined $pid) {
- throw Error::Simple("open failed: $!");
+ die "open failed: $!";
} elsif ($pid == 0) {
if (defined $opts{STDERR}) {
close STDERR;
--
1.7.9.5
next prev parent reply other threads:[~2012-05-19 7:09 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-26 4:15 Git.pm Subho Banerjee
2012-04-26 18:41 ` Git.pm Randal L. Schwartz
2012-04-26 18:58 ` Git.pm Tim Henigan
2012-04-26 20:10 ` Git.pm Subho Banerjee
2012-04-26 20:31 ` Git.pm Jonathan Nieder
2012-05-10 13:19 ` Git.pm Subho Banerjee
2012-05-10 15:16 ` Git.pm Jonathan Nieder
2012-05-10 15:54 ` Git.pm demerphq
2012-05-10 16:18 ` Git.pm Subho Banerjee
2012-05-10 17:22 ` Git.pm demerphq
2012-05-10 16:20 ` Git.pm Junio C Hamano
2012-05-10 17:38 ` Git.pm demerphq
2012-05-10 20:55 ` Git.pm Andrew Sayers
2012-05-11 8:27 ` Git.pm demerphq
2012-05-11 16:56 ` Git.pm Randal L. Schwartz
2012-05-11 18:10 ` Git.pm Junio C Hamano
2012-05-19 7:08 ` [PATCH][GIT.PM 1/3] Ignore files produced from exuberant-ctags Subho Sankar Banerjee
2012-05-19 7:08 ` Subho Sankar Banerjee [this message]
2012-05-19 9:38 ` [PATCH][GIT.PM 2/3] Getting rid of throwing Error::Simple objects in favour of simple Perl scalars which can be caught in eval{} blocks Andrew Sayers
2012-05-23 11:02 ` Subho Banerjee
2012-05-23 19:36 ` Andrew Sayers
2012-05-19 7:08 ` [PATCH][GIT.PM 3/3] Perl code uses eval{}/die instead of Error::Simple and Git::Error::Command Subho Sankar Banerjee
2012-04-26 19:17 ` Git.pm Junio C Hamano
2012-04-26 19:59 ` Git.pm Sam Vilain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337411317-14931-2-git-send-email-subs.zero@gmail.com \
--to=subs.zero@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.