[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:07 UTC 2009


The following commit has been merged in the master branch:
commit 319822af6d58c3e0c391e86cfd836ec31de43c67
Author: Luke Kanies <luke at madstop.com>
Date:   Wed Feb 11 14:33:48 2009 -0600

    Fixing #1869 - autoloaded files should never leak exceptions
    
    Ruby's exception hierarchy is a bit strange, in that only
    exceptions that sub RuntimeError are caught by default.
    This patch explicitly catches the base class, Exception,
    which means that LoadError, SyntaxError, and any
    RuntimeErrors will all be caught.
    
    This is done for both load() and loadall(); load() uses
    Kernel.load, but loadall() uses Kernel.require.
    
    Signed-off-by: Luke Kanies <luke at madstop.com>

diff --git a/CHANGELOG b/CHANGELOG
index 6b84df0..4294477 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,6 @@
 0.24.8
+    Fixing #1869 - autoloaded files should never leak exceptions
+
     Fixing #1543 - Nagios parse errors no longer kill Puppet
 
     Fixed #1420 - nagios_serviceescalation not allowing host_name more than one type
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index 535d9ef..0c80f8b 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -78,7 +78,7 @@ class Puppet::Util::Autoload
                 name = symbolize(name)
                 loaded name, file
                 return true
-            rescue LoadError => detail
+            rescue Exception => detail
                 # I have no idea what's going on here, but different versions
                 # of ruby are raising different errors on missing files.
                 unless detail.to_s =~ /^no such file/i
@@ -115,7 +115,7 @@ class Puppet::Util::Autoload
                 begin
                     Kernel.require file
                     loaded(name, file)
-                rescue => detail
+                rescue Exception => detail
                     if Puppet[:trace]
                         puts detail.backtrace
                     end
diff --git a/spec/unit/util/autoload.rb b/spec/unit/util/autoload.rb
new file mode 100755
index 0000000..ff717d6
--- /dev/null
+++ b/spec/unit/util/autoload.rb
@@ -0,0 +1,39 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/util/autoload'
+
+describe Puppet::Util::Autoload do
+    before do
+        @autoload = Puppet::Util::Autoload.new("foo", "tmp")
+
+        @autoload.stubs(:eachdir).yields "/my/dir"
+    end
+
+    describe "when loading a file" do
+        [RuntimeError, LoadError, SyntaxError].each do |error|
+            it "should not die an if a #{error.to_s} exception is thrown" do
+                FileTest.stubs(:exists?).returns true
+
+                Kernel.expects(:load).raises error
+
+                lambda { @autoload.load("foo") }.should_not raise_error
+            end
+        end
+    end
+
+    describe "when loading all files" do
+        before do
+            Dir.stubs(:glob).returns "file.rb"
+        end
+
+        [RuntimeError, LoadError, SyntaxError].each do |error|
+            it "should not die an if a #{error.to_s} exception is thrown" do
+                Kernel.expects(:require).raises error
+
+                lambda { @autoload.loadall }.should_not raise_error
+            end
+        end
+    end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list