From e5884a70e7d4c99c2bb0c581dc8a35b1cd4416cc Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 14 Nov 2025 11:39:09 +0100 Subject: [PATCH 1/3] Improved handling of unexpected exceptions In my case, I was encountering another exception, FileNotFoundError. This is not expected, and it makes sense to use the nicer printing instead of a big ugly stacktrace. In many cases the single line error message is enough, and the stacktrace doesn't add any value. You can still set the env var to get the full stacktrace. Signed-off-by: Ole Herman Schumacher Elgesem --- cf_remote/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cf_remote/main.py b/cf_remote/main.py index aebd27a..4d4dbd2 100644 --- a/cf_remote/main.py +++ b/cf_remote/main.py @@ -684,7 +684,7 @@ def main() -> int: print("Error: " + str(e)) except CFRExitError as e: print("Error: " + str(e)) - except (AssertionError, CFRProgrammerError) as e: + except (AssertionError, CFRProgrammerError, Exception) as e: print("Error: " + str(e)) print( "This is an unexpected error indicating a bug, please create a ticket at:" From 72ea955c4e53c904d5a68993000edc154b9a2053 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 14 Nov 2025 11:43:47 +0100 Subject: [PATCH 2/3] Ensured exiting error message is printed on separate line The exception could happen in the middle of something printing on a line, such as "Spawning...". In that case the error looks ugly and it's better to go to a new line. Signed-off-by: Ole Herman Schumacher Elgesem --- cf_remote/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cf_remote/main.py b/cf_remote/main.py index 4d4dbd2..eb9b231 100644 --- a/cf_remote/main.py +++ b/cf_remote/main.py @@ -681,11 +681,11 @@ def main() -> int: assert type(r) is int return r except CFRUserError as e: - print("Error: " + str(e)) + print("\nError: " + str(e)) except CFRExitError as e: - print("Error: " + str(e)) + print("\nError: " + str(e)) except (AssertionError, CFRProgrammerError, Exception) as e: - print("Error: " + str(e)) + print("\nError: " + str(e)) print( "This is an unexpected error indicating a bug, please create a ticket at:" ) From 5668ce3923d496314535991c1b2c1477cb0409d3 Mon Sep 17 00:00:00 2001 From: Ole Herman Schumacher Elgesem Date: Fri, 14 Nov 2025 12:58:57 +0100 Subject: [PATCH 3/3] Improved error message when VirtualBox is not installed Signed-off-by: Ole Herman Schumacher Elgesem --- cf_remote/spawn.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cf_remote/spawn.py b/cf_remote/spawn.py index 3fc098f..73b8805 100644 --- a/cf_remote/spawn.py +++ b/cf_remote/spawn.py @@ -20,7 +20,7 @@ from cf_remote.cloud_data import aws_image_criteria, aws_defaults from cf_remote.paths import cf_remote_dir, CLOUD_STATE_FPATH -from cf_remote.utils import whoami, copy_file, canonify, read_json +from cf_remote.utils import CFRUserError, whoami, copy_file, canonify, read_json from cf_remote import log from cf_remote import cloud_data @@ -822,10 +822,25 @@ def spawn_vm_in_vagrant( command_args.append("--no-provision") log.debug("Starting the VM(s)") - result = subprocess.run(command_args, env=vagrant_env, stderr=subprocess.PIPE) + try: + result = subprocess.run(command_args, env=vagrant_env, stderr=subprocess.PIPE) + except FileNotFoundError as e: + raise CFRUserError( + "'vagrant' not found - go to https://www.vagrantup.com/downloads to download and install vagrant ({}).".format( + e + ) + ) if result.returncode != 0: - raise Exception(result.stderr.decode()) + print() + log.error(result.stderr.decode()) + raise CFRUserError( + ( + "vagrant exited with error code {}" + + " - Make sure you have a working vagrant setup, install VirtualBox if you haven't already: " + + "https://www.virtualbox.org/wiki/Downloads" + ).format(result.returncode) + ) log.debug("Copying vagrant ssh config")