core: shorthand boxes must be foo/bar formatted, better errors

This commit is contained in:
Mitchell Hashimoto 2014-02-03 09:09:11 +01:00
parent 433e789a99
commit 647563edaf
4 changed files with 37 additions and 3 deletions

View File

@ -37,10 +37,14 @@ module Vagrant
# then expand it properly.
expanded = false
url.each_index do |i|
uri = URI.parse(url[i])
if !uri.scheme && !File.file?(url[i])
next if url[i] !~ /^[^\/]+\/[^\/]+$/
if !File.file?(url[i])
server = Vagrant.server_url
raise Errors::BoxServerNotSet if !server
expanded = true
url[i] = "#{Vagrant.server_url}/#{url[i]}"
url[i] = "#{server}/#{url[i]}"
end
end

View File

@ -204,6 +204,10 @@ module Vagrant
error_key(:box_remove_multi_version)
end
class BoxServerNotSet < VagrantError
error_key(:box_server_not_set)
end
class BoxUnpackageFailure < VagrantError
error_key(:untar_failure, "vagrant.actions.box.unpackage")
end

View File

@ -419,6 +419,17 @@ en:
the provider specified. Please double-check and try again.
The providers for this are: %{providers}
box_server_not_set: |-
A URL to a Vagrant Cloud server is not set, so boxes cannot
be added with a shorthand ("mitchellh/precise64") format.
You may also be seeing this error if you meant to type in
a path to a box file which doesn't exist locally on your
system.
To set a URL to a Vagrant Cloud server, set the
`VAGRANT_SERVER_URL` environmental variable. Or, if you
meant to use a file path, make sure the path to the file
is valid.
box_update_multi_provider: |-
You requested to update the box '%{name}'. This box has
multiple providers. You must explicitly select a single

View File

@ -262,6 +262,21 @@ describe Vagrant::Action::Builtin::BoxAdd do
end
end
it "raises an error if no Vagrant server is set" do
tf = Tempfile.new("foo")
tf.close
env[:box_url] = "mitchellh/precise64.json"
box_collection.should_receive(:add).never
app.should_receive(:call).never
Vagrant.stub(server_url: nil)
expect { subject.call(env) }.
to raise_error(Vagrant::Errors::BoxServerNotSet)
end
it "raises an error if shorthand is invalid" do
tf = Tempfile.new("foo")
tf.close