From dcd9c2a788ad4e160f586b4a9b2e58e2001d0000 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 24 Jul 2010 09:07:37 -0700 Subject: [PATCH] Give proper error message if bad URL given for HTTP box adding --- lib/vagrant/downloaders/http.rb | 2 ++ templates/strings.yml | 6 ++++++ test/test_helper.rb | 3 ++- test/vagrant/downloaders/http_test.rb | 8 ++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/vagrant/downloaders/http.rb b/lib/vagrant/downloaders/http.rb index fc11751a7..dc5be32d6 100644 --- a/lib/vagrant/downloaders/http.rb +++ b/lib/vagrant/downloaders/http.rb @@ -48,6 +48,8 @@ module Vagrant end env.logger.clear_progress + rescue SocketError + env.error!(:box_download_http_socket_error, :box_url => source_url) end end end diff --git a/templates/strings.yml b/templates/strings.yml index aea33e6b0..a2e313809 100644 --- a/templates/strings.yml +++ b/templates/strings.yml @@ -70,6 +70,12 @@ A box with the name '<%= box_name %>' already exists, please use another name or use `vagrant box remove <%= box_name %>` :box_download_unknown_type: |- Unknown URI type for box download. +:box_download_http_socket_error: |- + An error occurred while trying to download the specified box. This most + often happens if there is no internet connection or the address is + invalid. + + Box URL: <%= box_url %> :box_file_exists: |- The specified output file for packaging already exists. Please move the file or modify the output filename parameter then try to package diff --git a/test/test_helper.rb b/test/test_helper.rb index 386b544da..49b5a8653 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -121,7 +121,8 @@ class Test::Unit::TestCase tempfile = mock("tempfile") tempfile.stubs(:write) - [downloader_klass.new(mock_environment), tempfile] + _, env = mock_action_data + [downloader_klass.new(env), tempfile] end end diff --git a/test/vagrant/downloaders/http_test.rb b/test/vagrant/downloaders/http_test.rb index d48cc4557..b854fd6b6 100644 --- a/test/vagrant/downloaders/http_test.rb +++ b/test/vagrant/downloaders/http_test.rb @@ -42,6 +42,14 @@ class HttpDownloaderTest < Test::Unit::TestCase @downloader.download!(@uri, @tempfile) end + + should "error environment if invalid URL given" do + Net::HTTP.expects(:new).raises(SocketError.new) + @downloader.download!(@uri, @tempfile) + + assert @downloader.env.error? + assert_equal :box_download_http_socket_error, @downloader.env.error.first + end end context "matching the uri" do