providers/hyperv: better errors
This commit is contained in:
parent
a1958ee12f
commit
fb7dd73d95
|
@ -29,12 +29,7 @@ module VagrantPlugins
|
|||
}
|
||||
|
||||
env[:ui].info "Importing a Hyper-V instance"
|
||||
begin
|
||||
server = env[:machine].provider.driver.execute('import_vm.ps1', options)
|
||||
rescue Error::SubprocessError => e
|
||||
env[:ui].info e.message
|
||||
return
|
||||
end
|
||||
server = env[:machine].provider.driver.execute('import_vm.ps1', options)
|
||||
env[:ui].info "Successfully imported a VM with name #{server['name']}"
|
||||
env[:machine].id = server["id"]
|
||||
@app.call(env)
|
||||
|
|
|
@ -2,6 +2,8 @@ require "json"
|
|||
|
||||
require "vagrant/util/powershell"
|
||||
|
||||
require_relative "plugin"
|
||||
|
||||
module VagrantPlugins
|
||||
module HyperV
|
||||
class Driver
|
||||
|
@ -13,9 +15,15 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def execute(path, options)
|
||||
execute_powershell(path, options) do |type, data|
|
||||
r = execute_powershell(path, options) do |type, data|
|
||||
process_output(type, data)
|
||||
end
|
||||
if r.exit_code != 0
|
||||
raise Errors::PowerShellError,
|
||||
script: path,
|
||||
stderr: r.stderr
|
||||
end
|
||||
|
||||
if success?
|
||||
JSON.parse(json_output[:success].join) unless json_output[:success].empty?
|
||||
else
|
||||
|
|
|
@ -6,6 +6,10 @@ module VagrantPlugins
|
|||
error_namespace("vagrant_hyperv.errors")
|
||||
end
|
||||
|
||||
class PowerShellError < HyperVError
|
||||
error_key(:powershell_error)
|
||||
end
|
||||
|
||||
class PowerShellRequired < HyperVError
|
||||
error_key(:powershell_required)
|
||||
end
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
en:
|
||||
vagrant_hyperv:
|
||||
errors:
|
||||
powershell_error: |-
|
||||
An error occurred while executing a PowerShell script. This error
|
||||
is shown below. Please read the error message and see if this is
|
||||
a configuration error with your system. If it is not, then please
|
||||
report a bug.
|
||||
|
||||
Script: %{script}
|
||||
Error:
|
||||
|
||||
%{stderr}
|
||||
powershell_required: |-
|
||||
The Vagrant Hyper-V provider requires PowerShell to be available.
|
||||
Please make sure "powershell.exe" is available on your PATH.
|
||||
|
|
Loading…
Reference in New Issue