Raise an exception if a non-MachineState is returned

This commit is contained in:
Mitchell Hashimoto 2013-01-21 11:31:20 -06:00
parent 7bdf54923a
commit 8ad8f73846
4 changed files with 21 additions and 3 deletions

View File

@ -248,6 +248,10 @@ module Vagrant
error_key(:machine_not_found) error_key(:machine_not_found)
end end
class MachineStateInvalid < VagrantError
error_key(:machine_state_invalid)
end
class MultiVMEnvironmentRequired < VagrantError class MultiVMEnvironmentRequired < VagrantError
status_code(5) status_code(5)
error_key(:multi_vm_required) error_key(:multi_vm_required)

View File

@ -277,7 +277,9 @@ module Vagrant
# #
# @return [Symbol] # @return [Symbol]
def state def state
@provider.state result = @provider.state
raise Errors::MachineStateInvalid if !result.is_a?(MachineState)
result
end end
protected protected

View File

@ -145,6 +145,12 @@ en:
machine_not_found: |- machine_not_found: |-
The machine with the name '%{name}' was not found configured for The machine with the name '%{name}' was not found configured for
this Vagrant environment. this Vagrant environment.
machine_state_invalid: |-
An internal error has occurred! The provider of the machine you're
trying to work with reported an invalid state. This is a bug with
the provider you're using, and not with Vagrant itself or with
any configuration you may have done. Please report this bug to
the proper location.
multi_vm_required: |- multi_vm_required: |-
A multi-vm environment is required for name specification to this command. A multi-vm environment is required for name specification to this command.
multi_vm_target_required: |- multi_vm_target_required: |-

View File

@ -385,10 +385,16 @@ describe Vagrant::Machine do
describe "state" do describe "state" do
it "should query state from the provider" do it "should query state from the provider" do
state = :running state = Vagrant::MachineState.new(:id, "short", "long")
provider.should_receive(:state).and_return(state) provider.should_receive(:state).and_return(state)
instance.state.should == state instance.state.id.should == :id
end
it "should raise an exception if a MachineState is not returned" do
provider.should_receive(:state).and_return(:old_school)
expect { instance.state }.
to raise_error(Vagrant::Errors::MachineStateInvalid)
end end
end end
end end