2010-08-28 19:23:40 +00:00
|
|
|
# This file contains all of the internal errors in Vagrant's core
|
|
|
|
# commands, actions, etc.
|
|
|
|
|
2010-08-24 18:18:29 +00:00
|
|
|
module Vagrant
|
2010-08-27 06:21:28 +00:00
|
|
|
module Errors
|
|
|
|
# Main superclass of any errors in Vagrant. This provides some
|
|
|
|
# convenience methods for setting the status code and error key.
|
|
|
|
# The status code is used by the `vagrant` executable as the
|
|
|
|
# error code, and the error key is used as a default message from
|
|
|
|
# I18n.
|
|
|
|
class VagrantError < StandardError
|
2010-08-28 19:23:40 +00:00
|
|
|
DEFAULT_NAMESPACE = "vagrant.errors"
|
2010-08-28 20:54:59 +00:00
|
|
|
@@used_codes = []
|
2010-08-28 19:23:40 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
def self.status_code(code = nil)
|
2010-08-28 20:54:59 +00:00
|
|
|
if code
|
|
|
|
raise "Status code already in use: #{code}" if @@used_codes.include?(code)
|
|
|
|
@@used_codes << code
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
define_method(:status_code) { code }
|
|
|
|
end
|
|
|
|
|
2010-08-28 19:23:40 +00:00
|
|
|
def self.error_key(key=nil, namespace=nil)
|
2010-08-27 06:21:28 +00:00
|
|
|
define_method(:error_key) { key }
|
2010-08-28 19:23:40 +00:00
|
|
|
define_method(:error_namespace) { namespace } if namespace
|
2010-08-27 06:21:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(message=nil, *args)
|
|
|
|
message = translate_error(error_key, message) if respond_to?(:error_key)
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def translate_error(key, opts=nil)
|
2010-08-28 19:23:40 +00:00
|
|
|
namespace = respond_to?(:error_namespace) ? error_namespace : DEFAULT_NAMESPACE
|
|
|
|
I18n.t("#{namespace}.#{key}", opts)
|
2010-08-27 06:21:28 +00:00
|
|
|
end
|
2010-08-24 18:18:29 +00:00
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class BaseVMNotFound < VagrantError
|
2010-08-28 20:54:59 +00:00
|
|
|
status_code(18)
|
2010-08-27 06:21:28 +00:00
|
|
|
error_key(:base_vm_not_found)
|
2010-08-27 04:56:38 +00:00
|
|
|
end
|
|
|
|
|
2010-08-28 19:31:55 +00:00
|
|
|
class BoxAlreadyExists < VagrantError
|
|
|
|
status_code(14)
|
|
|
|
error_key(:already_exists, "vagrant.actions.box.unpackage")
|
|
|
|
end
|
|
|
|
|
2010-08-28 19:23:40 +00:00
|
|
|
class BoxDownloadUnknownType < VagrantError
|
|
|
|
status_code(13)
|
|
|
|
error_key(:unknown_type, "vagrant.actions.box.download")
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class BoxNotFound < VagrantError
|
|
|
|
status_code(2)
|
|
|
|
error_key(:box_not_found)
|
2010-08-27 04:56:38 +00:00
|
|
|
end
|
|
|
|
|
2010-08-31 02:39:11 +00:00
|
|
|
class BoxNotSpecified < VagrantError
|
|
|
|
status_code(22)
|
|
|
|
error_key(:not_specified, "vagrant.actions.vm.check_box")
|
|
|
|
end
|
|
|
|
|
|
|
|
class BoxSpecifiedDoesntExist < VagrantError
|
|
|
|
status_code(23)
|
|
|
|
error_key(:does_not_exist, "vagrant.actions.vm.check_box")
|
|
|
|
end
|
|
|
|
|
2010-08-28 19:31:55 +00:00
|
|
|
class BoxVerificationFailed < VagrantError
|
|
|
|
status_code(15)
|
|
|
|
error_key(:failed, "vagrant.actions.box.verify")
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class CLIMissingEnvironment < VagrantError
|
|
|
|
status_code(1)
|
|
|
|
error_key(:cli_missing_env)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class MultiVMEnvironmentRequired < VagrantError
|
|
|
|
status_code(5)
|
|
|
|
error_key(:multi_vm_required)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class MultiVMTargetRequired < VagrantError
|
|
|
|
status_code(7)
|
|
|
|
error_key(:multi_vm_target_required)
|
|
|
|
end
|
2010-08-24 18:18:29 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class NoEnvironmentError < VagrantError
|
|
|
|
status_code(3)
|
|
|
|
error_key(:no_env)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-28 20:54:59 +00:00
|
|
|
class PackageIncludeMissing < VagrantError
|
|
|
|
status_code(20)
|
|
|
|
error_key(:include_file_missing, "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
|
|
|
|
|
2010-08-27 07:01:27 +00:00
|
|
|
class SSHAuthenticationFailed < VagrantError
|
|
|
|
status_code(11)
|
|
|
|
error_key(:ssh_authentication_failed)
|
|
|
|
end
|
|
|
|
|
2010-08-27 07:05:03 +00:00
|
|
|
class SSHKeyBadPermissions < VagrantError
|
|
|
|
status_code(12)
|
|
|
|
error_key(:ssh_key_bad_permissions)
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:51:30 +00:00
|
|
|
class SSHUnavailableWindows < VagrantError
|
|
|
|
status_code(10)
|
|
|
|
error_key(:ssh_unavailable_windows)
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class VirtualBoxInvalidOSE < VagrantError
|
|
|
|
status_code(9)
|
|
|
|
error_key(:virtualbox_invalid_ose)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class VirtualBoxInvalidVersion < VagrantError
|
2010-08-28 20:54:59 +00:00
|
|
|
status_code(17)
|
2010-08-27 06:21:28 +00:00
|
|
|
error_key(:virtualbox_invalid_version)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class VirtualBoxNotDetected < VagrantError
|
|
|
|
status_code(8)
|
|
|
|
error_key(:virtualbox_not_detected)
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
|
2010-08-31 02:39:11 +00:00
|
|
|
class VMFailedToBoot < VagrantError
|
|
|
|
status_code(21)
|
|
|
|
error_key(:failed_to_boot, "vagrant.actions.vm.boot")
|
|
|
|
end
|
|
|
|
|
2010-08-27 06:21:28 +00:00
|
|
|
class VMNotCreatedError < VagrantError
|
|
|
|
status_code(6)
|
|
|
|
error_key(:vm_creation_required)
|
|
|
|
end
|
|
|
|
|
|
|
|
class VMNotFoundError < VagrantError
|
|
|
|
status_code(4)
|
|
|
|
error_key(:vm_not_found)
|
|
|
|
end
|
2010-08-31 02:39:11 +00:00
|
|
|
|
|
|
|
class VMPowerOffToPackage < VagrantError
|
|
|
|
status_code(24)
|
|
|
|
error_key(:power_off, "vagrant.actions.vm.export")
|
|
|
|
end
|
2010-08-27 04:56:38 +00:00
|
|
|
end
|
2010-08-24 18:18:29 +00:00
|
|
|
end
|