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