Merge pull request #2694 from tmatilai/plugin-json-errors

core: show more informative error if plugin.json parsing fails
This commit is contained in:
Mitchell Hashimoto 2013-12-28 13:12:59 -08:00
commit 5d39cc381f
4 changed files with 30 additions and 1 deletions

View File

@ -460,6 +460,10 @@ module Vagrant
error_key(:plugin_not_installed)
end
class PluginStateFileParseError < VagrantError
error_key(:plugin_state_file_not_parsable)
end
class SCPPermissionDenied < VagrantError
error_key(:scp_permission_denied)
end

View File

@ -10,7 +10,13 @@ module VagrantPlugins
@data = {}
if @path.exist?
@data = JSON.parse(@path.read)
begin
@data = JSON.parse(@path.read)
rescue JSON::ParserError => e
raise Vagrant::Errors::PluginStateFileParseError,
:path => path, :message => e.message
end
upgrade_v0! if !@data["version"]
end

View File

@ -501,6 +501,12 @@ en:
prior to attempting to do anything with it.
plugin_not_installed: |-
The plugin '%{name}' is not installed. Please install it first.
plugin_state_file_not_parsable: |-
Failed to parse the state file "%{path}":
%{message}
Please remove the file and reinstall the plugins.
If this error recurs, please report a bug.
port_collision_resume: |-
This VM cannot be resumed, because the forwarded ports would collide
with a running program (it could be another virtual machine). Normally,

View File

@ -70,4 +70,17 @@ describe VagrantPlugins::CommandPlugin::StateFile do
expect(plugins["foo"]["vagrant_version"]).to eql("0")
end
end
context "with parse errors" do
before do
path.open("w+") do |f|
f.write("I'm not json")
end
end
it "should raise a VagrantError" do
expect { subject }.
to raise_error(Vagrant::Errors::PluginStateFileParseError)
end
end
end