core: nicer error if shorthand can't be found
This commit is contained in:
parent
1bd3275b3b
commit
d08866e9f3
|
@ -26,12 +26,25 @@ module Vagrant
|
||||||
|
|
||||||
# If we received a shorthand URL ("mitchellh/precise64"),
|
# If we received a shorthand URL ("mitchellh/precise64"),
|
||||||
# then expand it properly.
|
# then expand it properly.
|
||||||
|
expanded = false
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
if !uri.scheme && !File.file?(url)
|
if !uri.scheme && !File.file?(url)
|
||||||
|
expanded = true
|
||||||
url = "#{Vagrant.server_url}/#{url}"
|
url = "#{Vagrant.server_url}/#{url}"
|
||||||
end
|
end
|
||||||
|
|
||||||
if metadata_url?(url, env)
|
is_metadata = false
|
||||||
|
begin
|
||||||
|
is_metadata = metadata_url?(url, env)
|
||||||
|
rescue Errors::DownloaderError => e
|
||||||
|
raise if !expanded
|
||||||
|
raise Errors::BoxAddShortNotFound,
|
||||||
|
error: e.extra_data[:message],
|
||||||
|
name: env[:box_url],
|
||||||
|
url: url
|
||||||
|
end
|
||||||
|
|
||||||
|
if is_metadata
|
||||||
add_from_metadata(url, env)
|
add_from_metadata(url, env)
|
||||||
else
|
else
|
||||||
add_direct(url, env)
|
add_direct(url, env)
|
||||||
|
|
|
@ -132,6 +132,10 @@ module Vagrant
|
||||||
error_key(:box_add_no_matching_version)
|
error_key(:box_add_no_matching_version)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class BoxAddShortNotFound < VagrantError
|
||||||
|
error_key(:box_add_short_not_found)
|
||||||
|
end
|
||||||
|
|
||||||
class BoxAlreadyExists < VagrantError
|
class BoxAlreadyExists < VagrantError
|
||||||
error_key(:box_add_exists)
|
error_key(:box_add_exists)
|
||||||
end
|
end
|
||||||
|
|
|
@ -247,6 +247,13 @@ en:
|
||||||
Address: %{url}
|
Address: %{url}
|
||||||
Constraints: %{constraints}
|
Constraints: %{constraints}
|
||||||
Available versions: %{versions}
|
Available versions: %{versions}
|
||||||
|
box_add_short_not_found: |-
|
||||||
|
The box '%{name}' could not be found or could not be accessed
|
||||||
|
in the remote catalog. Please double-check the name. The
|
||||||
|
expanded URL and error message are shown below.
|
||||||
|
|
||||||
|
URL: %{url}
|
||||||
|
Error: %{error}
|
||||||
boot_bad_state: |-
|
boot_bad_state: |-
|
||||||
The guest machine entered an invalid state while waiting for it
|
The guest machine entered an invalid state while waiting for it
|
||||||
to boot. Valid states are '%{valid}'. The machine is in the
|
to boot. Valid states are '%{valid}'. The machine is in the
|
||||||
|
|
|
@ -234,6 +234,21 @@ describe Vagrant::Action::Builtin::BoxAdd do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "raises an error if shorthand is invalid" do
|
||||||
|
tf = Tempfile.new("foo")
|
||||||
|
tf.close
|
||||||
|
|
||||||
|
with_web_server(Pathname.new(tf.path)) do |port|
|
||||||
|
env[:box_url] = "mitchellh/precise64.json"
|
||||||
|
|
||||||
|
box_collection.should_receive(:add).never
|
||||||
|
app.should_receive(:call).never
|
||||||
|
|
||||||
|
expect { subject.call(env) }.
|
||||||
|
to raise_error(Vagrant::Errors::BoxAddShortNotFound)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "adds the latest version of a box with only one provider" do
|
it "adds the latest version of a box with only one provider" do
|
||||||
box_path = iso_env.box2_file(:virtualbox)
|
box_path = iso_env.box2_file(:virtualbox)
|
||||||
tf = Tempfile.new("vagrant").tap do |f|
|
tf = Tempfile.new("vagrant").tap do |f|
|
||||||
|
|
Loading…
Reference in New Issue