Skip to content

Commit 6906ecc

Browse files
authored
Merge pull request #163 from olehermanse/master
Improved error messages in cf-remote spawn
2 parents fbe9970 + 5668ce3 commit 6906ecc

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

cf_remote/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,11 @@ def main() -> int:
681681
assert type(r) is int
682682
return r
683683
except CFRUserError as e:
684-
print("Error: " + str(e))
684+
print("\nError: " + str(e))
685685
except CFRExitError as e:
686-
print("Error: " + str(e))
687-
except (AssertionError, CFRProgrammerError) as e:
688-
print("Error: " + str(e))
686+
print("\nError: " + str(e))
687+
except (AssertionError, CFRProgrammerError, Exception) as e:
688+
print("\nError: " + str(e))
689689
print(
690690
"This is an unexpected error indicating a bug, please create a ticket at:"
691691
)

cf_remote/spawn.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
from cf_remote.cloud_data import aws_image_criteria, aws_defaults
2222
from cf_remote.paths import cf_remote_dir, CLOUD_STATE_FPATH
23-
from cf_remote.utils import whoami, copy_file, canonify, read_json
23+
from cf_remote.utils import CFRUserError, whoami, copy_file, canonify, read_json
2424
from cf_remote import log
2525
from cf_remote import cloud_data
2626

@@ -822,10 +822,25 @@ def spawn_vm_in_vagrant(
822822
command_args.append("--no-provision")
823823

824824
log.debug("Starting the VM(s)")
825-
result = subprocess.run(command_args, env=vagrant_env, stderr=subprocess.PIPE)
825+
try:
826+
result = subprocess.run(command_args, env=vagrant_env, stderr=subprocess.PIPE)
827+
except FileNotFoundError as e:
828+
raise CFRUserError(
829+
"'vagrant' not found - go to https://www.vagrantup.com/downloads to download and install vagrant ({}).".format(
830+
e
831+
)
832+
)
826833

827834
if result.returncode != 0:
828-
raise Exception(result.stderr.decode())
835+
print()
836+
log.error(result.stderr.decode())
837+
raise CFRUserError(
838+
(
839+
"vagrant exited with error code {}"
840+
+ " - Make sure you have a working vagrant setup, install VirtualBox if you haven't already: "
841+
+ "https://www.virtualbox.org/wiki/Downloads"
842+
).format(result.returncode)
843+
)
829844

830845
log.debug("Copying vagrant ssh config")
831846

0 commit comments

Comments
 (0)