diff --git a/plugins/providers/hyperv/action/import.rb b/plugins/providers/hyperv/action/import.rb index e7def6156..6cc0b0b42 100644 --- a/plugins/providers/hyperv/action/import.rb +++ b/plugins/providers/hyperv/action/import.rb @@ -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) diff --git a/plugins/providers/hyperv/driver.rb b/plugins/providers/hyperv/driver.rb index 9c0f2645e..a4cfcafa2 100644 --- a/plugins/providers/hyperv/driver.rb +++ b/plugins/providers/hyperv/driver.rb @@ -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 diff --git a/plugins/providers/hyperv/errors.rb b/plugins/providers/hyperv/errors.rb index e4f647e5c..d820198ab 100644 --- a/plugins/providers/hyperv/errors.rb +++ b/plugins/providers/hyperv/errors.rb @@ -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 diff --git a/templates/locales/providers_hyperv.yml b/templates/locales/providers_hyperv.yml index fb84baa3a..c3a47969c 100644 --- a/templates/locales/providers_hyperv.yml +++ b/templates/locales/providers_hyperv.yml @@ -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.