From f62b99e146fdde4645a68fd8ff470e514a1e0fec Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Fri, 7 Feb 2014 12:03:57 +0000
Subject: [PATCH] Switched to our internal implementation of throw() via
 Carp::confess. It is also available to Runnables as $self->throw( $msg );

---
 modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm      |  3 +--
 modules/Bio/EnsEMBL/Hive/AnalysisStats.pm         |  2 +-
 .../EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm    |  1 -
 modules/Bio/EnsEMBL/Hive/DBSQL/DBAdaptor.pm       |  5 ++---
 modules/Bio/EnsEMBL/Hive/DataflowRule.pm          |  4 +---
 modules/Bio/EnsEMBL/Hive/Process.pm               | 10 ++++++++--
 modules/Bio/EnsEMBL/Hive/Queen.pm                 |  8 ++++----
 modules/Bio/EnsEMBL/Hive/Utils.pm                 | 15 ++++++++++++++-
 8 files changed, 31 insertions(+), 17 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm b/modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
index 776d1348c..8d5187e9b 100644
--- a/modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
+++ b/modules/Bio/EnsEMBL/Hive/AnalysisCtrlRule.pm
@@ -43,8 +43,7 @@ package Bio::EnsEMBL::Hive::AnalysisCtrlRule;
 
 use strict;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
-
+use Bio::EnsEMBL::Hive::Utils ('throw');
 use Bio::EnsEMBL::Hive::URLFactory;
 
 use base ( 'Bio::EnsEMBL::Hive::Storable' );
diff --git a/modules/Bio/EnsEMBL/Hive/AnalysisStats.pm b/modules/Bio/EnsEMBL/Hive/AnalysisStats.pm
index 3843afbc6..ad4bb90ba 100644
--- a/modules/Bio/EnsEMBL/Hive/AnalysisStats.pm
+++ b/modules/Bio/EnsEMBL/Hive/AnalysisStats.pm
@@ -37,7 +37,7 @@ package Bio::EnsEMBL::Hive::AnalysisStats;
 
 use strict;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
+use Bio::EnsEMBL::Hive::Utils ('throw');
 use Bio::EnsEMBL::Hive::Analysis;
 
 use base ( 'Bio::EnsEMBL::Hive::Storable' );
diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
index f6c2ab577..93c761b22 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisStatsAdaptor.pm
@@ -43,7 +43,6 @@ package Bio::EnsEMBL::Hive::DBSQL::AnalysisStatsAdaptor;
 
 use strict;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
 use Bio::EnsEMBL::Hive::AnalysisStats;
 
 use base ('Bio::EnsEMBL::Hive::DBSQL::ObjectAdaptor');
diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/DBAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/DBAdaptor.pm
index 7bba5fafb..39f0cbb07 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/DBAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/DBAdaptor.pm
@@ -36,8 +36,7 @@ package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
 
 use strict;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
-
+use Bio::EnsEMBL::Hive::Utils ('throw');
 use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
 use Bio::EnsEMBL::Hive::DBSQL::SqlSchemaAdaptor;
 
@@ -190,7 +189,7 @@ sub get_adaptor {
 
     unless( $self->{'_cached_adaptor'}{$signature} ) {
         my $adaptor_package_name = $self->get_available_adaptors()->{$type}
-        or throw("Could not find a module corresponding to '$type'");
+            or throw("Could not find a module corresponding to '$type'");
 
         eval "require $adaptor_package_name"
         or throw("Could not load or compile module '$adaptor_package_name'");
diff --git a/modules/Bio/EnsEMBL/Hive/DataflowRule.pm b/modules/Bio/EnsEMBL/Hive/DataflowRule.pm
index 4c95dfc41..63421b4cc 100644
--- a/modules/Bio/EnsEMBL/Hive/DataflowRule.pm
+++ b/modules/Bio/EnsEMBL/Hive/DataflowRule.pm
@@ -53,9 +53,7 @@ package Bio::EnsEMBL::Hive::DataflowRule;
 
 use strict;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
-
-use Bio::EnsEMBL::Hive::Utils ('stringify');
+use Bio::EnsEMBL::Hive::Utils ('stringify', 'throw');
 use Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor;
 
 use base ( 'Bio::EnsEMBL::Hive::Storable' );
diff --git a/modules/Bio/EnsEMBL/Hive/Process.pm b/modules/Bio/EnsEMBL/Hive/Process.pm
index 769c3f612..06f784103 100644
--- a/modules/Bio/EnsEMBL/Hive/Process.pm
+++ b/modules/Bio/EnsEMBL/Hive/Process.pm
@@ -99,12 +99,11 @@ package Bio::EnsEMBL::Hive::Process;
 use strict;
 use warnings;
 
-use Bio::EnsEMBL::Utils::Exception ('throw');
-
 use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
 use Bio::EnsEMBL::Hive::Utils ('stringify', 'go_figure_dbc');
 use Bio::EnsEMBL::Hive::Utils::Stopwatch;
 
+
 use base ('Bio::EnsEMBL::Utils::Exception');   # provide these methods for deriving classes
 
 
@@ -491,6 +490,13 @@ sub dataflow_output_id {
 }
 
 
+sub throw {
+    my $msg = pop @_;
+
+    Bio::EnsEMBL::Hive::Utils::throw( $msg );   # this module doesn't import 'throw' to avoid namespace clash
+}
+
+
 =head2 debug
 
     Title   :  debug
diff --git a/modules/Bio/EnsEMBL/Hive/Queen.pm b/modules/Bio/EnsEMBL/Hive/Queen.pm
index eb11307b5..2d2aa0d94 100644
--- a/modules/Bio/EnsEMBL/Hive/Queen.pm
+++ b/modules/Bio/EnsEMBL/Hive/Queen.pm
@@ -212,7 +212,7 @@ sub specialize_new_worker {
     if($job_id or $analysis_id or $logic_name) {    # probably pre-specialized from command-line
 
         if($job_id) {
-            print "resetting and fetching job for job_id '$job_id'\n";
+            warn "resetting and fetching job for job_id '$job_id'\n";
 
             my $job_adaptor = $self->db->get_AnalysisJobAdaptor;
 
@@ -677,9 +677,9 @@ sub get_num_failed_analyses {
     my $filter_analysis_failed = 0;
 
     foreach my $failed_analysis (@$failed_analyses) {
-        print "\t##########################################################\n";
-        print "\t# Too many jobs in analysis '".$failed_analysis->logic_name."' FAILED #\n";
-        print "\t##########################################################\n\n";
+        warn "\t##########################################################\n";
+        warn "\t# Too many jobs in analysis '".$failed_analysis->logic_name."' FAILED #\n";
+        warn "\t##########################################################\n\n";
         if($filter_analysis and ($filter_analysis->dbID == $failed_analysis)) {
             $filter_analysis_failed = 1;
         }
diff --git a/modules/Bio/EnsEMBL/Hive/Utils.pm b/modules/Bio/EnsEMBL/Hive/Utils.pm
index 977314d14..1877b53a1 100644
--- a/modules/Bio/EnsEMBL/Hive/Utils.pm
+++ b/modules/Bio/EnsEMBL/Hive/Utils.pm
@@ -52,11 +52,15 @@ package Bio::EnsEMBL::Hive::Utils;
 
 use strict;
 use warnings;
+use Carp ('confess');
 use Data::Dumper;
 use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
 
 use Exporter 'import';
-our @EXPORT_OK = qw(stringify destringify dir_revhash parse_cmdline_options find_submodules load_file_or_module script_usage url2dbconn_hash go_figure_dbc);
+our @EXPORT_OK = qw(stringify destringify dir_revhash parse_cmdline_options find_submodules load_file_or_module script_usage url2dbconn_hash go_figure_dbc throw);
+
+no warnings ('once');   # otherwise the next line complains about $Carp::Internal being used just once
+$Carp::Internal{ (__PACKAGE__) }++;
 
 
 =head2 stringify
@@ -324,5 +328,14 @@ sub go_figure_dbc {
     }
 }
 
+
+sub throw {
+    my $msg = pop @_;
+
+        # TODO: newer versions of Carp are much more tunable, but I am stuck with v1.08 .
+        #       Alternatively, we could implement our own stack reporter instead of Carp::confess.
+    confess $msg;
+}
+
 1;
 
-- 
GitLab