From bdbd581c0db5a89424b57489ac2e5d326b73b63a Mon Sep 17 00:00:00 2001 From: Filippo Cremonese <filippocremonese@rev.ng> Date: Wed, 14 Oct 2020 13:06:44 +0200 Subject: [PATCH] Do not print stack trace when a component cannot be found --- orchestra/cmds/clean.py | 11 ++++++++++- orchestra/cmds/clone.py | 10 +++++++++- orchestra/cmds/components.py | 8 ++++++++ orchestra/cmds/configure.py | 10 +++++++++- orchestra/cmds/environment.py | 8 ++++++++ orchestra/cmds/graph.py | 11 ++++++++++- orchestra/cmds/install.py | 10 +++++++++- orchestra/cmds/shell.py | 8 ++++++++ orchestra/model/configuration.py | 3 +-- 9 files changed, 72 insertions(+), 7 deletions(-) diff --git a/orchestra/cmds/clean.py b/orchestra/cmds/clean.py index 79c05be..985862b 100644 --- a/orchestra/cmds/clean.py +++ b/orchestra/cmds/clean.py @@ -1,6 +1,9 @@ -from ..model.configuration import Configuration import shutil +from loguru import logger + +from ..model.configuration import Configuration + def install_subcommand(sub_argparser): cmd_parser = sub_argparser.add_parser("clean", handler=handle_clean, help="Remove build/source directories") @@ -10,6 +13,12 @@ def install_subcommand(sub_argparser): def handle_clean(args, config: Configuration): build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + if input(f"Do you want to clean {build.qualified_name}? [y/N] ").lower() != "y": return diff --git a/orchestra/cmds/clone.py b/orchestra/cmds/clone.py index a2de711..e183d95 100644 --- a/orchestra/cmds/clone.py +++ b/orchestra/cmds/clone.py @@ -1,5 +1,7 @@ -from ..model.configuration import Configuration +from loguru import logger + from ..executor import Executor +from ..model.configuration import Configuration def install_subcommand(sub_argparser): @@ -10,6 +12,12 @@ def install_subcommand(sub_argparser): def handle_clone(args, config: Configuration): build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + if not build.clone: print("This component does not have a git repository configured!") return diff --git a/orchestra/cmds/components.py b/orchestra/cmds/components.py index 6a63fb8..252af66 100644 --- a/orchestra/cmds/components.py +++ b/orchestra/cmds/components.py @@ -1,3 +1,5 @@ +from loguru import logger + from ..model.configuration import Configuration from ..util import get_installed_build @@ -13,6 +15,12 @@ def install_subcommand(sub_argparser): def handle_components(args, config: Configuration): if args.component: build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + components = {build.component.name: build.component} else: components = config.components diff --git a/orchestra/cmds/configure.py b/orchestra/cmds/configure.py index da7666e..e0704ee 100644 --- a/orchestra/cmds/configure.py +++ b/orchestra/cmds/configure.py @@ -1,5 +1,7 @@ -from ..model.configuration import Configuration +from loguru import logger + from ..executor import Executor +from ..model.configuration import Configuration def install_subcommand(sub_argparser): @@ -10,5 +12,11 @@ def install_subcommand(sub_argparser): def handle_configure(args, config: Configuration): build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + executor = Executor(args) executor.run(build.configure, force=args.force) diff --git a/orchestra/cmds/environment.py b/orchestra/cmds/environment.py index d086aa5..ad34d62 100644 --- a/orchestra/cmds/environment.py +++ b/orchestra/cmds/environment.py @@ -1,3 +1,5 @@ +from loguru import logger + from ..util import export_environment @@ -11,4 +13,10 @@ def handle_environment(args, config): print(export_environment(config.global_env())) else: build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + print(export_environment(build.install.environment)) diff --git a/orchestra/cmds/graph.py b/orchestra/cmds/graph.py index e074e13..ab10f88 100644 --- a/orchestra/cmds/graph.py +++ b/orchestra/cmds/graph.py @@ -1,3 +1,5 @@ +from loguru import logger + from ..model.configuration import Configuration @@ -10,7 +12,14 @@ def install_subcommand(sub_argparser): def handle_graph(args, config: Configuration): if args.component: - actions = [config.get_build(args.component).install] + build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + + actions = [build.install] else: actions = set() for component in config.components.values(): diff --git a/orchestra/cmds/install.py b/orchestra/cmds/install.py index 543ee11..0003bb9 100644 --- a/orchestra/cmds/install.py +++ b/orchestra/cmds/install.py @@ -1,5 +1,7 @@ -from ..model.configuration import Configuration +from loguru import logger + from ..executor import Executor +from ..model.configuration import Configuration def install_subcommand(sub_argparser): @@ -13,5 +15,11 @@ def install_subcommand(sub_argparser): def handle_install(args, config: Configuration): build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + executor = Executor(args) executor.run(build.install, force=args.force) diff --git a/orchestra/cmds/shell.py b/orchestra/cmds/shell.py index b3c320b..4fbc26b 100644 --- a/orchestra/cmds/shell.py +++ b/orchestra/cmds/shell.py @@ -6,6 +6,8 @@ import termios import tty from subprocess import Popen +from loguru import logger + from ..actions.util import run_script from ..model.configuration import Configuration from ..util import export_environment @@ -23,6 +25,12 @@ def handle_shell(args, config: Configuration): env["PS1"] = "(orchestra) $PS1" else: build = config.get_build(args.component) + + if not build: + suggested_component_name = config.get_suggested_component_name(args.component) + logger.error(f"Component {args.component} not found! Did you mean {suggested_component_name}?") + exit(1) + env = build.install.environment env["PS1"] = f"(orchestra - {build.qualified_name}) $PS1" diff --git a/orchestra/model/configuration.py b/orchestra/model/configuration.py index 93a28db..9774bed 100644 --- a/orchestra/model/configuration.py +++ b/orchestra/model/configuration.py @@ -68,8 +68,7 @@ class Configuration: component_name, build_name = parse_component_name(comp_spec) component = self.components.get(component_name) if not component: - suggested_component_name = self.get_suggested_component_name(component_name) - raise Exception(f"Component {component_name} not found! Did you mean {suggested_component_name}?") + return None if build_name: build = component.builds[build_name] else: -- GitLab