Don't need to call ".new" on raising exceptions

This commit is contained in:
Mitchell Hashimoto 2010-12-21 20:04:21 -08:00
parent 2358130c0e
commit 7c7f5d48fe
30 changed files with 68 additions and 68 deletions

View File

@ -94,7 +94,7 @@ module Vagrant
callable = callable_id
callable = Builder.new.use(callable_id) if callable_id.kind_of?(Class)
callable = self.class.actions[callable_id] if callable_id.kind_of?(Symbol)
raise ArgumentError.new("Argument to run must be a callable object or registered action.") if !callable || !callable.respond_to?(:call)
raise ArgumentError, "Argument to run must be a callable object or registered action." if !callable || !callable.respond_to?(:call)
action_environment = Action::Environment.new(env)
action_environment.merge!(options || {})

View File

@ -33,7 +33,7 @@ module Vagrant
end
end
raise Errors::BoxDownloadUnknownType.new if !@downloader
raise Errors::BoxDownloadUnknownType if !@downloader
@downloader.prepare(@env["box"].uri)
true

View File

@ -37,7 +37,7 @@ module Vagrant
end
def setup_box_directory
raise Errors::BoxAlreadyExists.new(:name => @env["box"].name) if File.directory?(@env["box"].directory)
raise Errors::BoxAlreadyExists, :name => @env["box"].name if File.directory?(@env["box"].directory)
FileUtils.mkdir_p(@env["box"].directory)
@box_directory = @env["box"].directory

View File

@ -12,7 +12,7 @@ module Vagrant
env.ui.info I18n.t("vagrant.actions.box.verify.verifying")
VirtualBox::Appliance.new(env["box"].ovf_file.to_s)
rescue Exception
raise Errors::BoxVerificationFailed.new
raise Errors::BoxVerificationFailed
end
@app.call(env)

View File

@ -28,8 +28,8 @@ module Vagrant
def call(env)
@env = env
raise Errors::PackageOutputExists.new if File.exist?(tar_path)
raise Errors::PackageRequiresDirectory.new if !@env["package.directory"] || !File.directory?(@env["package.directory"])
raise Errors::PackageOutputExists if File.exist?(tar_path)
raise Errors::PackageRequiresDirectory if !@env["package.directory"] || !File.directory?(@env["package.directory"])
verify_files_to_copy
compress
@ -57,7 +57,7 @@ module Vagrant
def verify_files_to_copy
files_to_copy.each do |file, _|
raise Errors::PackageIncludeMissing.new(:file => file) if !File.exist?(file)
raise Errors::PackageIncludeMissing, :file => file if !File.exist?(file)
end
end

View File

@ -12,7 +12,7 @@ module Vagrant
# Start up the VM and wait for it to boot.
boot
raise Errors::VMFailedToBoot.new if !wait_for_boot
raise Errors::VMFailedToBoot if !wait_for_boot
@app.call(env)
end

View File

@ -8,11 +8,11 @@ module Vagrant
def call(env)
box_name = env["config"].vm.box
raise Errors::BoxNotSpecified.new if !box_name
raise Errors::BoxNotSpecified if !box_name
if !env.env.boxes.find(box_name)
box_url = env["config"].vm.box_url
raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url
raise Errors::BoxSpecifiedDoesntExist, :name => box_name if !box_url
env.ui.info I18n.t("vagrant.actions.vm.check_box.not_found", :name => box_name)
Vagrant::Box.add(env.env, box_name, box_url)

View File

@ -14,7 +14,7 @@ module Vagrant
def call(env)
@env = env
raise Errors::VMPowerOffToPackage.new if !@env["vm"].vm.powered_off?
raise Errors::VMPowerOffToPackage if !@env["vm"].vm.powered_off?
setup_temp_dir
export

View File

@ -23,7 +23,7 @@ module Vagrant
# 1024, which causes the forwarded ports to fail.
def threshold_check
@env.env.config.vm.forwarded_ports.each do |name, options|
raise Errors::ForwardPortBelowThreshold.new if options[:hostport] <= 1024
raise Errors::ForwardPortBelowThreshold if options[:hostport] <= 1024
end
end
@ -47,9 +47,9 @@ module Vagrant
if !options[:auto]
# Auto fixing is disabled for this port forward, so we
# must throw an error so the user can fix it.
raise Errors::ForwardPortCollision.new(:name => name,
:host_port => options[:hostport].to_s,
:guest_port => options[:guestport].to_s)
raise Errors::ForwardPortCollision, :name => name,
:host_port => options[:hostport].to_s,
:guest_port => options[:guestport].to_s
end
# Get the auto port range and get rid of the used ports and
@ -60,10 +60,10 @@ module Vagrant
range -= existing_ports
if range.empty?
raise Errors::ForwardPortAutolistEmpty.new(:vm_name => @env["vm"].name,
:name => name,
:host_port => options[:hostport].to_s,
:guest_port => options[:guestport].to_s)
raise Errors::ForwardPortAutolistEmpty, :vm_name => @env["vm"].name,
:name => name,
:host_port => options[:hostport].to_s,
:guest_port => options[:guestport].to_s
end
# Set the port up to be the first one and add that port to

View File

@ -15,7 +15,7 @@ module Vagrant
end
# Flag as erroneous and return if import failed
raise Errors::VMImportFailure.new if !env["vm"].vm
raise Errors::VMImportFailure if !env["vm"].vm
# Import completed successfully. Continue the chain
@app.call(env)

View File

@ -13,7 +13,7 @@ module Vagrant
end
env["config"].vm.network_options.compact.each do |network_options|
raise Errors::NetworkCollision.new if !verify_no_bridge_collision(network_options)
raise Errors::NetworkCollision if !verify_no_bridge_collision(network_options)
end
end
@ -87,7 +87,7 @@ module Vagrant
end
end
raise Errors::NetworkNotFound.new(:name => net_options[:name]) if net_options[:name]
raise Errors::NetworkNotFound, :name => net_options[:name] if net_options[:name]
# One doesn't exist, create it.
@env.ui.info I18n.t("vagrant.actions.vm.network.creating")

View File

@ -147,9 +147,9 @@ module Vagrant
# Verifies that the host is set and supports NFS.
def verify_settings
raise Errors::NFSHostRequired.new if @env["host"].nil?
raise Errors::NFSNotSupported.new if !@env["host"].nfs?
raise Errors::NFSNoHostNetwork.new if @env["config"].vm.network_options.empty?
raise Errors::NFSHostRequired if @env["host"].nil?
raise Errors::NFSNotSupported if !@env["host"].nfs?
raise Errors::NFSNoHostNetwork if @env["config"].vm.network_options.empty?
end
end
end

View File

@ -28,7 +28,7 @@ module Vagrant
if provisioner.is_a?(Class)
@provisioner = provisioner.new(@env)
raise Errors::ProvisionInvalidClass.new if !@provisioner.is_a?(Provisioners::Base)
raise Errors::ProvisionInvalidClass if !@provisioner.is_a?(Provisioners::Base)
elsif provisioner.is_a?(Symbol)
# We have a few hard coded provisioners for built-ins
mapping = {
@ -38,7 +38,7 @@ module Vagrant
}
provisioner_klass = mapping[provisioner]
raise Errors::ProvisionUnknownType.new(:provisioner => provisioner.to_s) if provisioner_klass.nil?
raise Errors::ProvisionUnknownType, :provisioner => provisioner.to_s if provisioner_klass.nil?
@provisioner = provisioner_klass.new(@env)
end

View File

@ -24,9 +24,9 @@ module Vagrant
begin
# Call the next middleware in the sequence, appending to the stack
# of "recoverable" middlewares in case something goes wrong!
raise Errors::VagrantInterrupt.new if env.interrupted?
raise Errors::VagrantInterrupt if env.interrupted?
@stack.unshift(@actions.shift).first.call(env)
raise Errors::VagrantInterrupt.new if env.interrupted?
raise Errors::VagrantInterrupt if env.interrupted?
rescue SystemExit
# This means that an "exit" or "abort" was called. In these cases,
# we just exit immediately.

View File

@ -57,7 +57,7 @@ module Vagrant
# method requires that `name` and `uri` be set. The logic of this method
# is kicked out to the `box_add` registered middleware.
def add
raise Errors::BoxAlreadyExists.new(:name => name) if File.directory?(directory)
raise Errors::BoxAlreadyExists, :name => name if File.directory?(directory)
env.actions.run(:box_add, { "box" => self, "validate" => false })
end

View File

@ -11,14 +11,14 @@ module Vagrant
desc "remove NAME", "Remove a box from the system"
def remove(name)
b = env.boxes.find(name)
raise Errors::BoxNotFound.new(:name => name) if !b
raise Errors::BoxNotFound, :name => name if !b
b.destroy
end
desc "repackage NAME", "Repackage an installed box into a `.box` file."
def repackage(name)
b = env.boxes.find(name)
raise Errors::BoxNotFound.new(:name => name) if !b
raise Errors::BoxNotFound, :name => name if !b
b.repackage
end

View File

@ -4,14 +4,14 @@ module Vagrant
# Initializes the environment by pulling the environment out of
# the configuration hash and sets up the UI if necessary.
def initialize_environment(args, options, config)
raise Errors::CLIMissingEnvironment.new if !config[:env]
raise Errors::CLIMissingEnvironment if !config[:env]
@env = config[:env]
end
# This returns an array of {VM} objects depending on the arguments
# given to the command.
def target_vms(name=nil)
raise Errors::NoEnvironmentError.new if !env.root_path
raise Errors::NoEnvironmentError if !env.root_path
name ||= self.name rescue nil
@ -19,9 +19,9 @@ module Vagrant
if env.multivm?
return env.vms_ordered if !name
vm = env.vms[name.to_sym]
raise Errors::VMNotFoundError.new(:name => name) if !vm
raise Errors::VMNotFoundError, :name => name if !vm
else
raise Errors::MultiVMEnvironmentRequired.new if name
raise Errors::MultiVMEnvironmentRequired if name
vm = env.vms.values.first
end

View File

@ -16,14 +16,14 @@ module Vagrant
def package_base
vm = VM.find(options[:base], env)
raise Errors::BaseVMNotFound.new(:name => options[:base]) if !vm.created?
raise Errors::BaseVMNotFound, :name => options[:base] if !vm.created?
package_vm(vm)
end
def package_target
raise Errors::MultiVMTargetRequired.new(:command => "package") if target_vms.length > 1
raise Errors::MultiVMTargetRequired, :command => "package" if target_vms.length > 1
vm = target_vms.first
raise Errors::VMNotCreatedError.new if !vm.created?
raise Errors::VMNotCreatedError if !vm.created?
package_vm(vm)
end

View File

@ -24,15 +24,15 @@ module Vagrant
end
def ssh_connect
raise Errors::VMNotCreatedError.new if !ssh_vm.created?
raise Errors::VMNotRunningError.new if !ssh_vm.vm.running?
raise Errors::VMNotCreatedError if !ssh_vm.created?
raise Errors::VMNotRunningError if !ssh_vm.vm.running?
ssh_vm.ssh.connect
end
def ssh_vm
@ssh_vm ||= begin
vm = self.name.nil? && env.multivm? ? env.primary_vm : nil
raise Errors::MultiVMTargetRequired.new(:command => "ssh") if !vm && target_vms.length > 1
raise Errors::MultiVMTargetRequired, :command => "ssh" if !vm && target_vms.length > 1
vm = target_vms.first if !vm
vm
end

View File

@ -5,9 +5,9 @@ module Vagrant
register "ssh_config", "outputs .ssh/config valid syntax for connecting to this environment via ssh"
def execute
raise Errors::MultiVMTargetRequired.new(:command => "ssh_config") if target_vms.length > 1
raise Errors::MultiVMTargetRequired, :command => "ssh_config" if target_vms.length > 1
vm = target_vms.first
raise Errors::VMNotCreatedError.new if !vm.created?
raise Errors::VMNotCreatedError if !vm.created?
$stdout.puts(Util::TemplateRenderer.render("ssh_config", {
:host_key => options[:host] || "vagrant",

View File

@ -95,7 +95,7 @@ module Vagrant
load item
rescue SyntaxError => e
# Report syntax errors in a nice way for Vagrantfiles
raise Errors::VagrantfileSyntaxError.new(:file => e.message)
raise Errors::VagrantfileSyntaxError, :file => e.message
end
elsif item.is_a?(Proc)
self.class.run(&item)
@ -159,7 +159,7 @@ module Vagrant
end
return if errors.empty?
raise Errors::ConfigValidationFailed.new(:messages => Util::TemplateRenderer.render("config/validation_failed", :errors => errors))
raise Errors::ConfigValidationFailed, :messages => Util::TemplateRenderer.render("config/validation_failed", :errors => errors)
end
end
end

View File

@ -10,7 +10,7 @@ module Vagrant
end
def prepare(source_url)
raise Errors::DownloaderFileDoesntExist.new if !::File.file?(source_url)
raise Errors::DownloaderFileDoesntExist if !::File.file?(source_url)
end
def download!(source_url, destination_file)

View File

@ -48,7 +48,7 @@ module Vagrant
end
end
rescue SocketError
raise Errors::DownloaderHTTPSocketError.new
raise Errors::DownloaderHTTPSocketError
end
end
end

View File

@ -31,9 +31,9 @@ module Vagrant
# VirtualBox installed is high enough.
def check_virtualbox!
version = VirtualBox.version
raise Errors::VirtualBoxNotDetected.new if version.nil?
raise Errors::VirtualBoxInvalidVersion.new(:version => version.to_s) if version.to_f < 3.2
raise Errors::VirtualBoxInvalidOSE.new(:version => version.to_s) if version.to_s.downcase.include?("ose")
raise Errors::VirtualBoxNotDetected if version.nil?
raise Errors::VirtualBoxInvalidVersion, :version => version.to_s if version.to_f < 3.2
raise Errors::VirtualBoxInvalidOSE, :version => version.to_s if version.to_s.downcase.include?("ose")
rescue Errors::VirtualBoxNotDetected
# On 64-bit Windows, show a special error. This error is a subclass
# of VirtualBoxNotDetected, so libraries which use Vagrant can just

View File

@ -5,7 +5,7 @@ module Vagrant
# provisioner**. Instead, {ChefSolo} or {ChefServer} should be used.
class Chef < Base
def prepare
raise ChefError.new(:invalid_provisioner)
raise ChefError, :invalid_provisioner
end
def verify_binary(binary)

View File

@ -6,9 +6,9 @@ module Vagrant
# with a chef server.
class ChefServer < Chef
def prepare
raise ChefError.new(:server_validation_key_required) if env.config.chef.validation_key_path.nil?
raise ChefError.new(:server_validation_key_doesnt_exist) if !File.file?(validation_key_path)
raise ChefError.new(:server_url_required) if env.config.chef.chef_server_url.nil?
raise ChefError, :server_validation_key_required if env.config.chef.validation_key_path.nil?
raise ChefError, :server_validation_key_doesnt_exist if !File.file?(validation_key_path)
raise ChefError, :server_url_required if env.config.chef.chef_server_url.nil?
end
def provision!

View File

@ -63,7 +63,7 @@ module Vagrant
env.ui.info I18n.t("vagrant.provisioners.puppet.manifest_to_run", :manifest => @manifest)
return @manifest
else
raise PuppetError.new(:_key => :manifest_missing, :manifest => @manifest)
raise PuppetError, :_key => :manifest_missing, :manifest => @manifest
end
end

View File

@ -23,11 +23,11 @@ module Vagrant
# of options which override the configuration values.
def connect(opts={})
if Mario::Platform.windows?
raise Errors::SSHUnavailableWindows.new(:key_path => env.config.ssh.private_key_path,
:ssh_port => port(opts))
raise Errors::SSHUnavailableWindows, :key_path => env.config.ssh.private_key_path,
:ssh_port => port(opts)
end
raise Errors::SSHUnavailable.new if !Kernel.system("which ssh > /dev/null 2>&1")
raise Errors::SSHUnavailable if !Kernel.system("which ssh > /dev/null 2>&1")
options = {}
options[:port] = port(opts)
@ -74,7 +74,7 @@ module Vagrant
end
end
rescue Errno::ECONNREFUSED
raise Errors::SSHConnectionRefused.new
raise Errors::SSHConnectionRefused
end
# Uploads a file from `from` to `to`. `from` is expected to be a filename
@ -105,7 +105,7 @@ module Vagrant
true
rescue Net::SSH::AuthenticationFailed
raise Errors::SSHAuthenticationFailed.new
raise Errors::SSHAuthenticationFailed
rescue Timeout::Error, Errno::ECONNREFUSED, Net::SSH::Disconnect,
Errors::SSHConnectionRefused, Net::SSH::AuthenticationFailed
return false
@ -122,12 +122,12 @@ module Vagrant
if stat.owned? && file_perms(key_path) != "600"
File.chmod(0600, key_path)
raise Errors::SSHKeyBadPermissions.new(:key_path => key_path) if file_perms(key_path) != "600"
raise Errors::SSHKeyBadPermissions, :key_path => key_path if file_perms(key_path) != "600"
end
rescue Errno::EPERM
# This shouldn't happen since we verify we own the file, but just
# in case.
raise Errors::SSHKeyBadPermissions.new(:key_path => key_path)
raise Errors::SSHKeyBadPermissions, :key_path => key_path
end
# Returns the file permissions of a given file. This is fairly unix specific
@ -229,7 +229,7 @@ module Vagrant
:command => command
}.merge(options || {})
raise options[:_error_class].new(options)
raise options[:_error_class], options
end
end
end

View File

@ -106,7 +106,7 @@ module Vagrant
break unless result
attempts += 1
raise LinuxError.new(:mount_fail) if attempts >= 10
raise LinuxError, :mount_fail if attempts >= 10
sleep sleeptime
end
end

View File

@ -53,15 +53,15 @@ module Vagrant
if system.is_a?(Class)
@system = system.new(self)
raise Errors::VMSystemError.new(:_key => :invalid_class, :system => system.to_s) if !@system.is_a?(Systems::Base)
raise Errors::VMSystemError, :_key => :invalid_class, :system => system.to_s if !@system.is_a?(Systems::Base)
elsif system.is_a?(Symbol)
# Hard-coded internal systems
mapping = { :linux => Systems::Linux, :solaris => Systems::Solaris }
raise Errors::VMSystemError.new(:_key => :unknown_type, :system => system.to_s) if !mapping.has_key?(system)
raise Errors::VMSystemError, :_key => :unknown_type, :system => system.to_s if !mapping.has_key?(system)
@system = mapping[system].new(self)
else
raise Errors::VMSystemError.new(:unspecified)
raise Errors::VMSystemError, :unspecified
end
end