From a3395f94ab6f88e0eae54d8f9d454b687af11014 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 21 Dec 2011 16:37:59 -0800 Subject: [PATCH] Catch and handle customization errors --- lib/vagrant/action/vm/customize.rb | 8 +++++++- lib/vagrant/driver/virtualbox.rb | 2 +- lib/vagrant/errors.rb | 5 +++++ templates/locales/en.yml | 10 ++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/action/vm/customize.rb b/lib/vagrant/action/vm/customize.rb index 5469fb576..715dedfd5 100644 --- a/lib/vagrant/action/vm/customize.rb +++ b/lib/vagrant/action/vm/customize.rb @@ -18,7 +18,13 @@ module Vagrant arg end - env[:vm].driver.execute_command(processed_command) + result = env[:vm].driver.execute_command(processed_command) + if result.exit_code != 0 + raise Errors::VMCustomizationFailed, { + :command => processed_command.inspect, + :error => result.stderr + } + end end end diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index 6d43bdffc..deb17daa0 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -76,7 +76,7 @@ module Vagrant # Executes a raw command. def execute_command(command) - execute(*command) + raw(*command) end # Forwards a set of ports for a VM. diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 0fad2ec7f..7d1b099cc 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -334,6 +334,11 @@ module Vagrant error_key(:no_base_mac, "vagrant.actions.vm.match_mac") end + class VMCustomizationFailed < VagrantError + status_code(61) + error_key(:failure, "vagrant.actions.vm.customize") + end + class VMFailedToBoot < VagrantError status_code(21) error_key(:failed_to_boot, "vagrant.actions.vm.boot") diff --git a/templates/locales/en.yml b/templates/locales/en.yml index abfce1148..0e9550bc5 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -313,6 +313,16 @@ en: clear_shared_folders: deleting: Cleaning previously set shared folders... customize: + failure: |- + A customization command failed: + + %{command} + + The following error was experienced: + + %{error} + + Please fix this customization and try again. running: Running any VM customizations... destroy: destroying: Destroying VM and associated drives...