Remove ExceptionCatcher since exceptions are the way to report errors now
This commit is contained in:
parent
364233527e
commit
e7f06d7fb7
|
@ -32,7 +32,7 @@ I18n.load_path << File.expand_path("templates/locales/en.yml", Vagrant.source_ro
|
|||
libdir = File.expand_path("lib/vagrant", Vagrant.source_root)
|
||||
Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner
|
||||
downloaders/base config provisioners/base provisioners/chef systems/base
|
||||
action/exception_catcher hosts/base})
|
||||
hosts/base})
|
||||
|
||||
# Initialize the built-in actions
|
||||
Vagrant::Action.builtin!
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
class ActionException < Exception
|
||||
attr_reader :key
|
||||
attr_reader :data
|
||||
|
||||
def initialize(key, data = {})
|
||||
@key = key
|
||||
@data = data
|
||||
|
||||
message = Vagrant::Util::Translator.t(key, data)
|
||||
super(message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,14 +0,0 @@
|
|||
module Vagrant
|
||||
class Action
|
||||
# A helper to catch any ActionExceptions raised and to
|
||||
# apply the error to the environment.
|
||||
module ExceptionCatcher
|
||||
def catch_action_exception(env)
|
||||
yield env
|
||||
rescue ActionException => e
|
||||
env.error!(e.key, e.data)
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,8 +2,6 @@ module Vagrant
|
|||
class Action
|
||||
module VM
|
||||
class Halt
|
||||
include ExceptionCatcher
|
||||
|
||||
def initialize(app, env, options=nil)
|
||||
@app = app
|
||||
env.merge!(options || {})
|
||||
|
@ -11,10 +9,7 @@ module Vagrant
|
|||
|
||||
def call(env)
|
||||
if env["vm"].vm.running?
|
||||
if !env["force"]
|
||||
catch_action_exception(env) { env["vm"].system.halt }
|
||||
return if env.error?
|
||||
end
|
||||
env["vm"].system.halt if !env["force"]
|
||||
|
||||
if env["vm"].vm.state(true) != :powered_off
|
||||
env.ui.info "vagrant.actions.vm.halt.force"
|
||||
|
|
|
@ -4,8 +4,6 @@ module Vagrant
|
|||
# Networking middleware for Vagrant. This enables host only
|
||||
# networking on VMs if configured as such.
|
||||
class Network
|
||||
include ExceptionCatcher
|
||||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@env = env
|
||||
|
@ -22,7 +20,6 @@ module Vagrant
|
|||
@app.call(env)
|
||||
|
||||
if enable_network?
|
||||
catch_action_exception(env) do
|
||||
@env.ui.info "vagrant.actions.vm.network.enabling"
|
||||
@env["vm"].system.prepare_host_only_network
|
||||
@env.env.config.vm.network_options.compact.each do |network_options|
|
||||
|
@ -30,7 +27,6 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Verifies that there is no collision with a bridged network interface
|
||||
# for the given network options.
|
||||
|
|
|
@ -16,7 +16,6 @@ module Vagrant
|
|||
# folder.
|
||||
#
|
||||
class NFS
|
||||
include ExceptionCatcher
|
||||
include NFSHelpers
|
||||
|
||||
def initialize(app,env)
|
||||
|
@ -107,19 +106,15 @@ module Vagrant
|
|||
def export_folders
|
||||
@env.ui.info "vagrant.actions.vm.nfs.exporting"
|
||||
|
||||
catch_action_exception(@env) do
|
||||
@env["host"].nfs_export(guest_ip, folders)
|
||||
end
|
||||
end
|
||||
|
||||
# Uses the system class to mount the NFS folders.
|
||||
def mount_folders
|
||||
@env.ui.info "vagrant.actions.vm.nfs.mounting"
|
||||
|
||||
catch_action_exception(@env) do
|
||||
@env["vm"].system.mount_nfs(host_ip, folders)
|
||||
end
|
||||
end
|
||||
|
||||
# Returns the IP address of the first host only network adapter
|
||||
#
|
||||
|
|
|
@ -2,8 +2,6 @@ module Vagrant
|
|||
class Action
|
||||
module VM
|
||||
class ShareFolders
|
||||
include ExceptionCatcher
|
||||
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
@env = env
|
||||
|
@ -16,10 +14,8 @@ module Vagrant
|
|||
|
||||
@app.call(env)
|
||||
|
||||
catch_action_exception(env) do
|
||||
mount_shared_folders
|
||||
end
|
||||
end
|
||||
|
||||
# This method returns an actual list of VirtualBox shared
|
||||
# folders to create and their proper path.
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
require "test_helper"
|
||||
|
||||
class ExceptionCatcherTest < Test::Unit::TestCase
|
||||
setup do
|
||||
@klass = Class.new
|
||||
@klass.send(:include, Vagrant::Action::ExceptionCatcher)
|
||||
@env = Vagrant::Action::Environment.new(mock_environment)
|
||||
|
||||
@instance = @klass.new
|
||||
end
|
||||
|
||||
should "run block and return result if no exception" do
|
||||
result = @instance.catch_action_exception(@env) do
|
||||
true
|
||||
end
|
||||
|
||||
assert result
|
||||
assert !@env.error?
|
||||
end
|
||||
|
||||
should "run block and return false with error environment on exception" do
|
||||
result = @instance.catch_action_exception(@env) do
|
||||
raise Vagrant::Action::ActionException.new(:foo, :foo => :bar)
|
||||
end
|
||||
|
||||
assert !result
|
||||
assert @env.error?
|
||||
assert_equal :foo, @env.error.first
|
||||
end
|
||||
end
|
|
@ -144,13 +144,6 @@ class NFSVMActionTest < Test::Unit::TestCase
|
|||
@env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders)
|
||||
@instance.export_folders
|
||||
end
|
||||
|
||||
should "error the environment if exception is raised" do
|
||||
@env["host"].expects(:nfs_export).raises(Vagrant::Action::ActionException.new(:foo))
|
||||
@instance.export_folders
|
||||
assert @env.error?
|
||||
assert_equal :foo, @env.error.first
|
||||
end
|
||||
end
|
||||
|
||||
context "mounting folders" do
|
||||
|
|
Loading…
Reference in New Issue