deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 1/3] Make sure the exception DSL does not override
Date Fri, 21 Sep 2012 22:33:22 GMT
From: Michal Fojtik <mfojtik@redhat.com>

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.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/drivers/base_driver.rb |  4 ----
 server/lib/deltacloud/drivers/exceptions.rb  | 18 +++++++++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 3b37721..934c912 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 }
diff --git a/server/lib/deltacloud/drivers/exceptions.rb b/server/lib/deltacloud/drivers/exceptions.rb
index 5e679a5..1a635ce 100644
--- a/server/lib/deltacloud/drivers/exceptions.rb
+++ b/server/lib/deltacloud/drivers/exceptions.rb
@@ -171,9 +171,15 @@ module Deltacloud
       end
     end
 
-    def self.exceptions(&block)
-      @definitions = Exceptions.new(&block).exception_definitions if block_given?
-      @definitions
+    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)
@@ -181,7 +187,7 @@ module Deltacloud
         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
@@ -191,7 +197,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
-- 
1.7.12


Mime
View raw message