Get rid of error "status codes" and just exit with 1

This commit is contained in:
Mitchell Hashimoto 2013-02-03 18:04:43 -08:00
parent 036fa3e96a
commit 5d75a65382
1 changed files with 6 additions and 85 deletions

View File

@ -43,17 +43,6 @@ module Vagrant
# error code, and the error key is used as a default message from
# I18n.
class VagrantError < StandardError
@@used_codes = []
def self.status_code(code = nil)
if code
raise "Status code already in use: #{code}" if @@used_codes.include?(code)
@@used_codes << code
end
define_method(:status_code) { code }
end
def self.error_key(key=nil, namespace=nil)
define_method(:error_key) { key }
error_namespace(namespace) if namespace
@ -80,6 +69,12 @@ module Vagrant
# {error_key} method but can be overridden here if needed.
def error_key; nil; end
# This is the exit code that should be used when exiting from
# this exception.
#
# @return [Integer]
def status_code; 1; end
protected
def translate_error(opts)
@ -93,27 +88,22 @@ module Vagrant
end
class BaseVMNotFound < VagrantError
status_code(18)
error_key(:base_vm_not_found)
end
class BoxAlreadyExists < VagrantError
status_code(14)
error_key(:already_exists, "vagrant.actions.box.unpackage")
end
class BoxDownloadUnknownType < VagrantError
status_code(13)
error_key(:unknown_type, "vagrant.actions.box.download")
end
class BoxNotFound < VagrantError
status_code(2)
error_key(:box_not_found)
end
class BoxNotSpecified < VagrantError
status_code(22)
error_key(:not_specified, "vagrant.actions.vm.check_box")
end
@ -122,12 +112,10 @@ module Vagrant
end
class BoxSpecifiedDoesntExist < VagrantError
status_code(23)
error_key(:does_not_exist, "vagrant.actions.vm.check_box")
end
class BoxUnpackageFailure < VagrantError
status_code(57)
error_key(:untar_failure, "vagrant.actions.box.unpackage")
end
@ -136,17 +124,14 @@ module Vagrant
end
class BoxVerificationFailed < VagrantError
status_code(15)
error_key(:failed, "vagrant.actions.box.verify")
end
class CLIInvalidUsage < VagrantError
status_code(69)
error_key(:cli_invalid_usage)
end
class CLIInvalidOptions < VagrantError
status_code(1)
error_key(:cli_invalid_options)
end
@ -159,12 +144,10 @@ module Vagrant
end
class DestroyRequiresForce < VagrantError
status_code(74)
error_key(:destroy_requires_force)
end
class DotfileIsDirectory < VagrantError
status_code(46)
error_key(:dotfile_is_directory)
end
@ -173,7 +156,6 @@ module Vagrant
end
class DownloaderFileDoesntExist < VagrantError
status_code(37)
error_key(:file_missing, "vagrant.downloaders.file")
end
@ -182,57 +164,46 @@ module Vagrant
end
class DownloaderHTTPConnectTimeout < VagrantError
status_code(79)
error_key(:connection_timeout, "vagrant.downloaders.http")
end
class DownloaderHTTPSocketError < VagrantError
status_code(38)
error_key(:socket_error, "vagrant.downloaders.http")
end
class DownloaderHTTPStatusError < VagrantError
status_code(51)
error_key(:status_error, "vagrant.downloaders.http")
end
class EnvironmentNonExistentCWD < VagrantError
status_code(75)
error_key(:environment_non_existent_cwd)
end
class EnvironmentLockedError < VagrantError
status_code(52)
error_key(:environment_locked)
end
class GemCommandInBundler < VagrantError
status_code(71)
error_key(:gem_command_in_bundler)
end
class HomeDirectoryMigrationFailed < VagrantError
status_code(53)
error_key(:home_dir_migration_failed)
end
class HomeDirectoryNotAccessible < VagrantError
status_code(55)
error_key(:home_dir_not_accessible)
end
class ForwardPortAutolistEmpty < VagrantError
status_code(27)
error_key(:auto_empty, "vagrant.actions.vm.forward_ports")
end
class ForwardPortCollision < VagrantError
status_code(26)
error_key(:collision_error, "vagrant.actions.vm.forward_ports")
end
class ForwardPortCollisionResume < VagrantError
status_code(62)
error_key(:port_collision_resume)
end
@ -253,82 +224,66 @@ module Vagrant
end
class MultiVMEnvironmentRequired < VagrantError
status_code(5)
error_key(:multi_vm_required)
end
class MultiVMTargetRequired < VagrantError
status_code(7)
error_key(:multi_vm_target_required)
end
class NetworkAdapterCollision < VagrantError
status_code(65)
error_key(:adapter_collision, "vagrant.actions.vm.network")
end
class NetworkCollision < VagrantError
status_code(29)
error_key(:collides, "vagrant.actions.vm.host_only_network")
end
class NetworkNoAdapters < VagrantError
status_code(64)
error_key(:no_adapters, "vagrant.actions.vm.network")
end
class NetworkDHCPAlreadyAttached < VagrantError
status_code(68)
error_key(:dhcp_already_attached, "vagrant.actions.vm.network")
end
class NetworkNotFound < VagrantError
status_code(30)
error_key(:not_found, "vagrant.actions.vm.host_only_network")
end
class NFSHostRequired < VagrantError
status_code(31)
error_key(:host_required, "vagrant.actions.vm.nfs")
end
class NFSNotSupported < VagrantError
status_code(32)
error_key(:not_supported, "vagrant.actions.vm.nfs")
end
class NFSNoHostNetwork < VagrantError
status_code(33)
error_key(:no_host_network, "vagrant.actions.vm.nfs")
end
class NoEnvironmentError < VagrantError
status_code(3)
error_key(:no_env)
end
class PackageIncludeMissing < VagrantError
status_code(20)
error_key(:include_file_missing, "vagrant.actions.general.package")
end
class PackageOutputDirectory < VagrantError
status_code(72)
error_key(:output_is_directory, "vagrant.actions.general.package")
end
class PackageOutputExists < VagrantError
status_code(16)
error_key(:output_exists, "vagrant.actions.general.package")
end
class PackageRequiresDirectory < VagrantError
status_code(19)
error_key(:requires_directory, "vagrant.actions.general.package")
end
class PersistDotfileExists < VagrantError
status_code(34)
error_key(:dotfile_error, "vagrant.actions.vm.persist")
end
@ -349,7 +304,6 @@ module Vagrant
end
class PluginLoadError < VagrantError
status_code(81)
error_key(:plugin_load_error)
end
@ -358,37 +312,30 @@ module Vagrant
end
class SCPPermissionDenied < VagrantError
status_code(82)
error_key(:scp_permission_denied)
end
class SCPUnavailable < VagrantError
status_code(56)
error_key(:scp_unavailable)
end
class SharedFolderCreateFailed < VagrantError
status_code(66)
error_key(:shared_folder_create_failed)
end
class SSHAuthenticationFailed < VagrantError
status_code(11)
error_key(:ssh_authentication_failed)
end
class SSHConnectionRefused < VagrantError
status_code(43)
error_key(:ssh_connection_refused)
end
class SSHConnectionTimeout < VagrantError
status_code(78)
error_key(:ssh_connection_timeout)
end
class SSHDisconnected < VagrantError
status_code(83)
error_key(:ssh_disconnected)
end
@ -397,12 +344,10 @@ module Vagrant
end
class SSHKeyBadPermissions < VagrantError
status_code(12)
error_key(:ssh_key_bad_permissions)
end
class SSHKeyTypeNotSupported < VagrantError
status_code(76)
error_key(:ssh_key_type_not_supported)
end
@ -411,22 +356,18 @@ module Vagrant
end
class SSHPortNotDetected < VagrantError
status_code(50)
error_key(:ssh_port_not_detected)
end
class SSHUnavailable < VagrantError
status_code(45)
error_key(:ssh_unavailable)
end
class SSHUnavailableWindows < VagrantError
status_code(10)
error_key(:ssh_unavailable_windows)
end
class UIExpectsTTY < VagrantError
status_code(73)
error_key(:ui_expects_tty)
end
@ -435,12 +376,10 @@ module Vagrant
end
class VagrantInterrupt < VagrantError
status_code(40)
error_key(:interrupted)
end
class VagrantfileExistsError < VagrantError
status_code(58)
error_key(:vagrantfile_exists)
end
@ -449,17 +388,14 @@ module Vagrant
end
class VagrantfileSyntaxError < VagrantError
status_code(41)
error_key(:vagrantfile_syntax_error)
end
class VBoxManageError < VagrantError
status_code(59)
error_key(:vboxmanage_error)
end
class VirtualBoxInvalidVersion < VagrantError
status_code(17)
error_key(:virtualbox_invalid_version)
end
@ -468,52 +404,42 @@ module Vagrant
end
class VirtualBoxNotDetected < VagrantError
status_code(8)
error_key(:virtualbox_not_detected)
end
class VirtualBoxKernelModuleNotLoaded < VagrantError
status_code(70)
error_key(:virtualbox_kernel_module_not_loaded)
end
class VirtualBoxInstallIncomplete < VagrantError
status_code(80)
error_key(:virtualbox_install_incomplete)
end
class VMBaseMacNotSpecified < VagrantError
status_code(47)
error_key(:no_base_mac, "vagrant.actions.vm.match_mac")
end
class VMCustomizationFailed < VagrantError
status_code(61)
error_key(:failure, "vagrant.actions.vm.customize")
end
class VMFailedToBoot < VagrantError
status_code(21)
error_key(:failed_to_boot, "vagrant.actions.vm.boot")
end
class VMFailedToRun < VagrantError
status_code(77)
error_key(:failed_to_run, "vagrant.actions.vm.boot")
end
class VMGuestError < VagrantError
status_code(39)
error_namespace("vagrant.errors.guest")
end
class VMImportFailure < VagrantError
status_code(28)
error_key(:failure, "vagrant.actions.vm.import")
end
class VMInaccessible < VagrantError
status_code(54)
error_key(:vm_inaccessible)
end
@ -522,27 +448,22 @@ module Vagrant
end
class VMNoMatchError < VagrantError
status_code(63)
error_key(:vm_no_match)
end
class VMNotCreatedError < VagrantError
status_code(6)
error_key(:vm_creation_required)
end
class VMNotFoundError < VagrantError
status_code(4)
error_key(:vm_not_found)
end
class VMNotRunningError < VagrantError
status_code(44)
error_key(:vm_not_running)
end
class VMPowerOffToPackage < VagrantError
status_code(24)
error_key(:power_off, "vagrant.actions.vm.export")
end
end