deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [3/3] git commit: Make sure the exception DSL does not override
Date Wed, 26 Sep 2012 21:12:37 GMT
Make sure the exception DSL does not override

This patch fixed the case when the exception DSL is
used more than once (typically on driver switching).
In that case the new exceptions will override the exceptions
from the previous driver.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/243c0ac1
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/243c0ac1
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/243c0ac1

Branch: refs/heads/master
Commit: 243c0ac144a72054e6c4961d8a8748676a3ecc11
Parents: 96a2fc0
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Sat Sep 22 00:06:33 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Sep 26 23:09:50 2012 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/base_driver.rb |    4 ----
 server/lib/deltacloud/drivers/exceptions.rb  |   17 +++++++++++++++--
 2 files changed, 15 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/243c0ac1/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 068ff59..34c561c 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -64,10 +64,6 @@ module Deltacloud
       self.class.name.split('::').last.gsub('Driver', '').downcase
     end
 
-    def self.exceptions(&block)
-      ExceptionHandler::exceptions(&block)
-    end
-
     def self.define_hardware_profile(profile_id, &block)
       @hardware_profiles ||= []
       hw_profile = @hardware_profiles.find{|e| e.id == profile_id }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/243c0ac1/server/lib/deltacloud/drivers/exceptions.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/exceptions.rb b/server/lib/deltacloud/drivers/exceptions.rb
index 4b135bd..368891a 100644
--- a/server/lib/deltacloud/drivers/exceptions.rb
+++ b/server/lib/deltacloud/drivers/exceptions.rb
@@ -177,12 +177,23 @@ module Deltacloud
       @definitions
     end
 
+    module DSL
+      def exceptions(&block)
+        @definitions = Exceptions.new(&block).exception_definitions if block_given?
+        @definitions
+      end
+    end
+
+    def self.included(klass)
+      klass.extend(DSL)
+    end
+
     def safely(&block)
       begin
         block.call
       rescue
         report_method = $stderr.respond_to?(:err) ? :err : :puts
-        Deltacloud::ExceptionHandler::exceptions.each do |exdef|
+        self.class.exceptions.each do |exdef|
           if exdef.match?($!)
             new_exception = exdef.handler($!)
             m = (new_exception && !new_exception.message.nil?) ? new_exception.message
: $!.message
@@ -192,7 +203,9 @@ module Deltacloud
             raise exdef.handler($!) unless new_exception.nil?
           end
         end
-        $stderr.send(report_method, "[NO HANDLED] #{[$!.class.to_s, $!.message].join(': ')}\n#{$!.backtrace.join("\n")}")
+        unless ENV['RACK_ENV'] == 'test'
+          $stderr.send(report_method, "[NO HANDLED] #{[$!.class.to_s, $!.message].join(':
')}\n#{$!.backtrace.join("\n")}")
+        end
         raise Deltacloud::ExceptionHandler::BackendError.new($!, "Unhandled exception or
status code (#{$!.message})")
       end
     end


Mime
View raw message