From 853e51e0d683ae2825bddd2ef55763568b6c0056 Mon Sep 17 00:00:00 2001 From: Arunmozhi Date: Mon, 12 Aug 2024 11:05:41 +1000 Subject: [PATCH] refactor: improve error handling --- tutor/commands/config.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tutor/commands/config.py b/tutor/commands/config.py index 8beb300371..d74fd95f33 100644 --- a/tutor/commands/config.py +++ b/tutor/commands/config.py @@ -227,22 +227,21 @@ def patches_list(context: Context) -> None: @click.command(name="edit", help="Edit config.yml of the current environment") @click.pass_obj def edit(context: Context) -> None: - config_file = os.path.join(context.root, "config.yml") + config_file = tutor_config.config_path(context.root) + + if not os.path.isfile(config_file): + raise exceptions.TutorError(f"Missing config file at {config_file}") open_cmd = None - if which("open"): # MacOS + if which("open"): # MacOS & linux distributions that ship `open`. eg., Ubuntu open_cmd = ["open", config_file] elif which("xdg-open"): # Linux open_cmd = ["xdg-open", config_file] elif which("start"): # Windows open_cmd = ["start", '""', config_file] else: - click.echo( - "Cannot find a way to open the editor automatically. Kindly open the file manually: " - + config_file - ) - return + raise exceptions.TutorError(f"Failed to find utility to launch an editor.") subprocess.call(open_cmd)