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