Remove ExceptionCatcher since exceptions are the way to report errors now

This commit is contained in:
Mitchell Hashimoto 2010-09-01 10:04:37 -07:00
parent 364233527e
commit e7f06d7fb7
9 changed files with 9 additions and 94 deletions

View File

@ -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) libdir = File.expand_path("lib/vagrant", Vagrant.source_root)
Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner
downloaders/base config provisioners/base provisioners/chef systems/base downloaders/base config provisioners/base provisioners/chef systems/base
action/exception_catcher hosts/base}) hosts/base})
# Initialize the built-in actions # Initialize the built-in actions
Vagrant::Action.builtin! Vagrant::Action.builtin!

View File

@ -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

View File

@ -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

View File

@ -2,8 +2,6 @@ module Vagrant
class Action class Action
module VM module VM
class Halt class Halt
include ExceptionCatcher
def initialize(app, env, options=nil) def initialize(app, env, options=nil)
@app = app @app = app
env.merge!(options || {}) env.merge!(options || {})
@ -11,10 +9,7 @@ module Vagrant
def call(env) def call(env)
if env["vm"].vm.running? if env["vm"].vm.running?
if !env["force"] env["vm"].system.halt if !env["force"]
catch_action_exception(env) { env["vm"].system.halt }
return if env.error?
end
if env["vm"].vm.state(true) != :powered_off if env["vm"].vm.state(true) != :powered_off
env.ui.info "vagrant.actions.vm.halt.force" env.ui.info "vagrant.actions.vm.halt.force"

View File

@ -4,8 +4,6 @@ module Vagrant
# Networking middleware for Vagrant. This enables host only # Networking middleware for Vagrant. This enables host only
# networking on VMs if configured as such. # networking on VMs if configured as such.
class Network class Network
include ExceptionCatcher
def initialize(app, env) def initialize(app, env)
@app = app @app = app
@env = env @env = env
@ -22,7 +20,6 @@ module Vagrant
@app.call(env) @app.call(env)
if enable_network? if enable_network?
catch_action_exception(env) do
@env.ui.info "vagrant.actions.vm.network.enabling" @env.ui.info "vagrant.actions.vm.network.enabling"
@env["vm"].system.prepare_host_only_network @env["vm"].system.prepare_host_only_network
@env.env.config.vm.network_options.compact.each do |network_options| @env.env.config.vm.network_options.compact.each do |network_options|
@ -30,7 +27,6 @@ module Vagrant
end end
end end
end end
end
# Verifies that there is no collision with a bridged network interface # Verifies that there is no collision with a bridged network interface
# for the given network options. # for the given network options.

View File

@ -16,7 +16,6 @@ module Vagrant
# folder. # folder.
# #
class NFS class NFS
include ExceptionCatcher
include NFSHelpers include NFSHelpers
def initialize(app,env) def initialize(app,env)
@ -107,19 +106,15 @@ module Vagrant
def export_folders def export_folders
@env.ui.info "vagrant.actions.vm.nfs.exporting" @env.ui.info "vagrant.actions.vm.nfs.exporting"
catch_action_exception(@env) do
@env["host"].nfs_export(guest_ip, folders) @env["host"].nfs_export(guest_ip, folders)
end end
end
# Uses the system class to mount the NFS folders. # Uses the system class to mount the NFS folders.
def mount_folders def mount_folders
@env.ui.info "vagrant.actions.vm.nfs.mounting" @env.ui.info "vagrant.actions.vm.nfs.mounting"
catch_action_exception(@env) do
@env["vm"].system.mount_nfs(host_ip, folders) @env["vm"].system.mount_nfs(host_ip, folders)
end end
end
# Returns the IP address of the first host only network adapter # Returns the IP address of the first host only network adapter
# #

View File

@ -2,8 +2,6 @@ module Vagrant
class Action class Action
module VM module VM
class ShareFolders class ShareFolders
include ExceptionCatcher
def initialize(app, env) def initialize(app, env)
@app = app @app = app
@env = env @env = env
@ -16,10 +14,8 @@ module Vagrant
@app.call(env) @app.call(env)
catch_action_exception(env) do
mount_shared_folders mount_shared_folders
end end
end
# This method returns an actual list of VirtualBox shared # This method returns an actual list of VirtualBox shared
# folders to create and their proper path. # folders to create and their proper path.

View File

@ -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

View File

@ -144,13 +144,6 @@ class NFSVMActionTest < Test::Unit::TestCase
@env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders) @env["host"].expects(:nfs_export).with(@instance.guest_ip, @instance.folders)
@instance.export_folders @instance.export_folders
end 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 end
context "mounting folders" do context "mounting folders" do