Replace straight abort on interrupt with clean exit via exception
This commit is contained in:
parent
d0bd47a5d7
commit
60c20565b2
|
@ -8,7 +8,7 @@ begin
|
|||
Vagrant::CLI.start(ARGV, :env => env)
|
||||
rescue Vagrant::Errors::VagrantError => e
|
||||
opts = { :_translate => false, :_prefix => false }
|
||||
env.ui.error e.message, opts
|
||||
env.ui.error e.message, opts if e.message
|
||||
env.ui.error e.backtrace.join("\n"), opts if ENV["VAGRANT_DEBUG"]
|
||||
exit e.status_code if e.respond_to?(:status_code)
|
||||
exit 999 # An error occurred with no status code defined
|
||||
|
|
|
@ -35,7 +35,7 @@ module Vagrant
|
|||
act.recover(env) if act.respond_to?(:recover)
|
||||
end
|
||||
|
||||
exit if env.interrupted?
|
||||
raise Errors::VagrantInterrupt.new if env.interrupted?
|
||||
end
|
||||
|
||||
def finalize_action(action, env)
|
||||
|
|
|
@ -32,7 +32,7 @@ module Vagrant
|
|||
def initialize(message=nil, *args)
|
||||
message = { :_key => message } if message && !message.is_a?(Hash)
|
||||
message = { :_key => error_key, :_namespace => error_namespace }.merge(message || {})
|
||||
message = translate_error(message)
|
||||
message = translate_error(message) if message[:_key]
|
||||
|
||||
super
|
||||
end
|
||||
|
@ -44,7 +44,7 @@ module Vagrant
|
|||
|
||||
# The key for the error message. This should be set using the
|
||||
# {error_key} method but can be overridden here if needed.
|
||||
def error_key; ""; end
|
||||
def error_key; nil; end
|
||||
|
||||
protected
|
||||
|
||||
|
@ -203,6 +203,10 @@ module Vagrant
|
|||
error_key(:ssh_unavailable_windows)
|
||||
end
|
||||
|
||||
class VagrantInterrupt < VagrantError
|
||||
status_code(40)
|
||||
end
|
||||
|
||||
class VirtualBoxInvalidOSE < VagrantError
|
||||
status_code(9)
|
||||
error_key(:virtualbox_invalid_ose)
|
||||
|
|
|
@ -80,10 +80,11 @@ class ActionWardenTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "call exit if the environment is interupted" do
|
||||
@instance.expects(:exit)
|
||||
env = new_env
|
||||
env.expects(:interrupted?).returns(true)
|
||||
@instance.begin_rescue(env)
|
||||
assert_raises(Vagrant::Errors::VagrantInterrupt) {
|
||||
@instance.begin_rescue(env)
|
||||
}
|
||||
end
|
||||
|
||||
context "with many middleware" do
|
||||
|
|
Loading…
Reference in New Issue