From f9b1d52ec6435dea764c3753c725c2877e716b5c Mon Sep 17 00:00:00 2001 From: sophia Date: Thu, 10 Sep 2020 15:56:08 -0500 Subject: [PATCH] Catch error for when guest is not available --- lib/vagrant/action/builtin/synced_folders.rb | 10 ++++++++-- .../unit/vagrant/action/builtin/synced_folders_test.rb | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/action/builtin/synced_folders.rb b/lib/vagrant/action/builtin/synced_folders.rb index f799d2560..d516d1657 100644 --- a/lib/vagrant/action/builtin/synced_folders.rb +++ b/lib/vagrant/action/builtin/synced_folders.rb @@ -129,8 +129,14 @@ module Vagrant save_synced_folders(env[:machine], original_folders, **save_opts) end - # Persist the mounts by adding them to fstab - if env[:machine].guest.capability?(:persist_mount_shared_folder) + # Persist the mounts by adding them to fstab (only if the guest is available) + begin + persist_mount = env[:machine].guest.capability?(:persist_mount_shared_folder) + rescue Errors::MachineGuestNotReady + persist_mount = false + end + if persist_mount + # Persist the mounts by adding them to fstab if env[:machine].config.vm.allow_fstab_modification fstab_folders = original_folders else diff --git a/test/unit/vagrant/action/builtin/synced_folders_test.rb b/test/unit/vagrant/action/builtin/synced_folders_test.rb index 7d8357c27..c1ade4d83 100644 --- a/test/unit/vagrant/action/builtin/synced_folders_test.rb +++ b/test/unit/vagrant/action/builtin/synced_folders_test.rb @@ -255,5 +255,13 @@ describe Vagrant::Action::Builtin::SyncedFolders do subject.call(env) end end + + context "when guest is not available" do + it "does not persist folders if guest is not available" do + allow(machine).to receive_message_chain(:guest, :capability?).and_raise(Vagrant::Errors::MachineGuestNotReady) + expect(vm_config).to_not receive(:allow_fstab_modification) + subject.call(env) + end + end end end