[carton] 92/472: Handle errors correctly

Lucas Kanashiro kanashiro-guest at moszumanska.debian.org
Fri Jul 24 00:38:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

kanashiro-guest pushed a commit to branch master
in repository carton.

commit c56bdb0747e4120bb4b0838694ebc5667612cd02
Author: Tatsuhiko Miyagawa <miyagawa at bulknews.net>
Date:   Fri Jul 1 13:53:10 2011 -0700

    Handle errors correctly
---
 lib/Carton/CLI.pm    | 14 ++++++++++----
 lib/Carton/Config.pm |  3 +++
 lib/Carton/Error.pm  |  9 +++++++++
 3 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/lib/Carton/CLI.pm b/lib/Carton/CLI.pm
index ab1b2a0..eb9fcad 100644
--- a/lib/Carton/CLI.pm
+++ b/lib/Carton/CLI.pm
@@ -2,15 +2,15 @@ package Carton::CLI;
 use strict;
 use warnings;
 
-use Carton;
-use Carton::Util;
-
 use Cwd;
 use Config;
 use Getopt::Long;
 use Term::ANSIColor qw(colored);
 
+use Carton;
+use Carton::Util;
 use Carton::Config;
+use Carton::Error;
 use Carton::Tree;
 use Try::Tiny;
 
@@ -75,7 +75,12 @@ sub run {
     my $call = $self->can("cmd_$cmd");
 
     if ($call) {
-        $self->$call(@commands);
+        try {
+            $self->$call(@commands);
+        } catch {
+            /Carton::Error::CommandExit/ and return;
+            die $_;
+        }
     } else {
         die "Could not find command '$cmd'\n";
     }
@@ -123,6 +128,7 @@ sub print {
 sub error {
     my($self, $msg) = @_;
     $self->print($msg, ERROR);
+    Carton::Error::CommandExit->throw;
 }
 
 sub cmd_help {
diff --git a/lib/Carton/Config.pm b/lib/Carton/Config.pm
index 816958b..1690261 100644
--- a/lib/Carton/Config.pm
+++ b/lib/Carton/Config.pm
@@ -42,5 +42,8 @@ sub set {
     $self->SUPER::set(%args);
 }
 
+no Any::Moose;
+__PACKAGE__->meta->make_immutable;
+
 1;
 
diff --git a/lib/Carton/Error.pm b/lib/Carton/Error.pm
new file mode 100644
index 0000000..cd81376
--- /dev/null
+++ b/lib/Carton/Error.pm
@@ -0,0 +1,9 @@
+package Carton::Error;
+use strict;
+use Any::Moose;
+
+package Carton::Error::CommandExit;
+use Any::Moose;
+extends 'Carton::Error';
+
+1;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/carton.git



More information about the Pkg-perl-cvs-commits mailing list