Downloaders now raise exceptions instead of erroring environment
This commit is contained in:
parent
a7197b3566
commit
cf91f578fb
|
@ -10,9 +10,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
def prepare(source_url)
|
||||
if !::File.file?(source_url)
|
||||
return env.error!(:downloader_file_doesnt_exist, :source_url => source_url)
|
||||
end
|
||||
raise Errors::DownloaderFileDoesntExist.new if !::File.file?(source_url)
|
||||
end
|
||||
|
||||
def download!(source_url, destination_file)
|
||||
|
|
|
@ -46,7 +46,7 @@ module Vagrant
|
|||
end
|
||||
end
|
||||
rescue SocketError
|
||||
env.error!(:box_download_http_socket_error, :box_url => source_url)
|
||||
raise Errors::DownloaderHTTPSocketError.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -79,6 +79,16 @@ module Vagrant
|
|||
error_key(:cli_missing_env)
|
||||
end
|
||||
|
||||
class DownloaderFileDoesntExist < VagrantError
|
||||
status_code(37)
|
||||
error_key(:file_missing, "vagrant.downloaders.file")
|
||||
end
|
||||
|
||||
class DownloaderHTTPSocketError < VagrantError
|
||||
status_code(38)
|
||||
error_key(:socket_error, "vagrant.downloaders.http")
|
||||
end
|
||||
|
||||
class ForwardPortAutolistEmpty < VagrantError
|
||||
status_code(27)
|
||||
error_key(:auto_empty, "vagrant.actions.vm.forward_ports")
|
||||
|
|
|
@ -278,6 +278,15 @@ en:
|
|||
include_file_missing: |-
|
||||
Package include file doesn't exist: %{file}
|
||||
|
||||
downloaders:
|
||||
file:
|
||||
file_missing: "The specified path to a file doesn't exist."
|
||||
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.
|
||||
|
||||
hosts:
|
||||
bsd:
|
||||
nfs_export:
|
||||
|
|
|
@ -7,12 +7,6 @@
|
|||
#---------------------------------------------------------------------
|
||||
# CATEGORY: Error Messages
|
||||
#---------------------------------------------------------------------
|
||||
: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
|
||||
|
@ -52,10 +46,6 @@
|
|||
vagrant box add name uri
|
||||
vagrant box remove name
|
||||
vagrant box list
|
||||
:downloader_file_doesnt_exist: |-
|
||||
The given box does not exist on the file system:
|
||||
|
||||
<%= source_url %>
|
||||
:package_requires_export: |-
|
||||
Package must be used in conjunction with export.
|
||||
:ssh_bad_exit_status: |-
|
||||
|
|
|
@ -9,9 +9,10 @@ class FileDownloaderTest < Test::Unit::TestCase
|
|||
context "preparing" do
|
||||
should "raise an exception if the file does not exist" do
|
||||
File.expects(:file?).with(@uri).returns(false)
|
||||
@downloader.prepare(@uri)
|
||||
assert @downloader.env.error?
|
||||
assert_equal :downloader_file_doesnt_exist, @downloader.env.error.first
|
||||
|
||||
assert_raises(Vagrant::Errors::DownloaderFileDoesntExist) {
|
||||
@downloader.prepare(@uri)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -45,10 +45,10 @@ class HttpDownloaderTest < Test::Unit::TestCase
|
|||
|
||||
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
|
||||
assert_raises(Vagrant::Errors::DownloaderHTTPSocketError) {
|
||||
@downloader.download!(@uri, @tempfile)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue