Merge pull request #2694 from tmatilai/plugin-json-errors
core: show more informative error if plugin.json parsing fails
This commit is contained in:
commit
5d39cc381f
|
@ -460,6 +460,10 @@ module Vagrant
|
||||||
error_key(:plugin_not_installed)
|
error_key(:plugin_not_installed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class PluginStateFileParseError < VagrantError
|
||||||
|
error_key(:plugin_state_file_not_parsable)
|
||||||
|
end
|
||||||
|
|
||||||
class SCPPermissionDenied < VagrantError
|
class SCPPermissionDenied < VagrantError
|
||||||
error_key(:scp_permission_denied)
|
error_key(:scp_permission_denied)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,7 +10,13 @@ module VagrantPlugins
|
||||||
|
|
||||||
@data = {}
|
@data = {}
|
||||||
if @path.exist?
|
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"]
|
upgrade_v0! if !@data["version"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -501,6 +501,12 @@ en:
|
||||||
prior to attempting to do anything with it.
|
prior to attempting to do anything with it.
|
||||||
plugin_not_installed: |-
|
plugin_not_installed: |-
|
||||||
The plugin '%{name}' is not installed. Please install it first.
|
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: |-
|
port_collision_resume: |-
|
||||||
This VM cannot be resumed, because the forwarded ports would collide
|
This VM cannot be resumed, because the forwarded ports would collide
|
||||||
with a running program (it could be another virtual machine). Normally,
|
with a running program (it could be another virtual machine). Normally,
|
||||||
|
|
|
@ -70,4 +70,17 @@ describe VagrantPlugins::CommandPlugin::StateFile do
|
||||||
expect(plugins["foo"]["vagrant_version"]).to eql("0")
|
expect(plugins["foo"]["vagrant_version"]).to eql("0")
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue