From 58f73104449edd0293a3df4259aae7370edac3da Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 21 Oct 2014 15:56:10 -0700 Subject: [PATCH] providers/virtualbox: detect conflict in name [GH-4681] --- CHANGELOG.md | 7 +++++++ lib/vagrant/errors.rb | 4 ++++ plugins/providers/virtualbox/driver/version_4_3.rb | 7 +++++++ templates/locales/en.yml | 12 ++++++++++++ 4 files changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c36f99a3..20d51ce31 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.7.0 (unreleased) + +BUG FIXES: + + - providers/virtualbox: Show a human-friendly error if VirtualBox didn't + clean up an existing VM. [GH-4681] + ## 1.6.5 (September 4, 2014) BUG FIXES: diff --git a/lib/vagrant/errors.rb b/lib/vagrant/errors.rb index 8995f6505..7fb23da1d 100644 --- a/lib/vagrant/errors.rb +++ b/lib/vagrant/errors.rb @@ -728,6 +728,10 @@ module Vagrant error_key(:virtualbox_no_name) end + class VirtualBoxNameExists < VagrantError + error_key(:virtualbox_name_exists) + end + class VMBaseMacNotSpecified < VagrantError error_key(:no_base_mac, "vagrant.actions.vm.match_mac") end diff --git a/plugins/providers/virtualbox/driver/version_4_3.rb b/plugins/providers/virtualbox/driver/version_4_3.rb index cc700c0fa..9f7527023 100644 --- a/plugins/providers/virtualbox/driver/version_4_3.rb +++ b/plugins/providers/virtualbox/driver/version_4_3.rb @@ -475,6 +475,13 @@ module VagrantPlugins def set_name(name) execute("modifyvm", @uuid, "--name", name, retryable: true) + rescue Vagrant::Errors::VBoxManageError => e + raise if !e.extra_data[:stderr].include?("VERR_ALREADY_EXISTS") + + # We got VERR_ALREADY_EXISTS. This means that we're renaming to + # a VM name that already exists. Raise a custom error. + raise Vagrant::Errors::VirtualBoxNameExists, + stderr: e.extra_data[:stderr] end def share_folders(folders) diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 47f80fac5..19ee8131f 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1193,6 +1193,18 @@ en: VirtualBox is complaining that the installation is incomplete. Please run `VBoxManage --version` to see the error message which should contain instructions on how to fix this error. + virtualbox_name_exists: |- + The name of your virtual machine couldn't be set because VirtualBox + is reporting another VM with that name already exists. Most of the + time, this is because of an error with VirtualBox not cleaning up + properly. To fix this, verify that no VMs with that name do exist + (by opening the VirtualBox GUI). If they don't, then look at the + folder in the error message from VirtualBox below and remove it + if there isn't any information you need in there. + + VirtualBox error: + + %{stderr} virtualbox_no_name: |- Vagrant was unable to determine the recommended name for your VirtualBox VM. This is usually an issue with VirtualBox. The output