Be smarter about determining if plugin load failed
This commit is contained in:
parent
9750069312
commit
1b6538354d
|
@ -169,9 +169,18 @@ module Vagrant
|
|||
# Attempt the normal require
|
||||
begin
|
||||
require name
|
||||
rescue LoadError
|
||||
raise Errors::PluginLoadError, :plugin => name
|
||||
rescue Exception => e
|
||||
# If it is a LoadError we first try to see if it failed loading
|
||||
# the top-level entrypoint. If so, then we report a different error.
|
||||
if e.is_a?(LoadError)
|
||||
# Parse the message in order to get what failed to load, and
|
||||
# add some extra protection around if the message is different.
|
||||
parts = e.to_s.split(" -- ", 2)
|
||||
if parts.length == 2 && parts[1] == name
|
||||
raise Errors::PluginLoadError, :plugin => name
|
||||
end
|
||||
end
|
||||
|
||||
# Since this is a rare case, we create a one-time logger here
|
||||
# in order to output the error
|
||||
logger = Log4r::Logger.new("vagrant::root")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require File.expand_path("../base", __FILE__)
|
||||
|
||||
describe Vagrant do
|
||||
include_context "unit"
|
||||
|
||||
it "has the path to the source root" do
|
||||
described_class.source_root.should == Pathname.new(File.expand_path("../../../", __FILE__))
|
||||
end
|
||||
|
@ -39,5 +41,16 @@ describe Vagrant do
|
|||
expect { described_class.require_plugin("i_dont_exist") }.
|
||||
to raise_error(Vagrant::Errors::PluginLoadError)
|
||||
end
|
||||
|
||||
it "should raise an error if the loading failed in some other way" do
|
||||
plugin_dir = temporary_dir
|
||||
plugin_path = plugin_dir.join("test.rb")
|
||||
plugin_path.open("w") do |f|
|
||||
f.write(%Q[require 'I_dont_exist'])
|
||||
end
|
||||
|
||||
expect { described_class.require_plugin(plugin_path.to_s) }.
|
||||
to raise_error(Vagrant::Errors::PluginLoadFailed)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue