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