From 4e8e6d88f3729fc22441ea8e38a6010f4087dc06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Araujo?= Date: Thu, 23 Jan 2020 03:45:35 -0500 Subject: Use tighter except blocks (#3) --- taskipy/run.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/taskipy/run.py b/taskipy/run.py index ff2db44..014d0ae 100644 --- a/taskipy/run.py +++ b/taskipy/run.py @@ -20,13 +20,14 @@ def run_task(task_name: str, args: List[str], cwd=os.curdir): except FileNotFoundError: print('no pyproject.toml file found in this directory') sys.exit(1) - except: + except toml.TomlDecodeError: print('pyproject.toml file is malformed and could not be read') + # should print exception details sys.exit(1) try: tasks = pyproject['tool']['taskipy']['tasks'] - except: + except KeyError: print('no tasks found. add a [tool.taskipy.tasks] section to your pyproject.toml') sys.exit(127) @@ -34,22 +35,23 @@ def run_task(task_name: str, args: List[str], cwd=os.curdir): try: task = tasks[task_name] - command_with_passed_args = ' '.join([task] + args) - commands.append(command_with_passed_args) - except: + except KeyError: print(f'could not find task "{task_name}""') sys.exit(127) + command_with_passed_args = ' '.join([task] + args) + commands.append(command_with_passed_args) + try: pre_task = tasks[f'pre_{task_name}'] commands.insert(0, pre_task) - except: + except KeyError: pass try: post_task = tasks[f'post_{task_name}'] commands.append(post_task) - except: + except KeyError: pass exit_code = run_commands_and_bail_on_first_fail(commands) -- cgit v1.2.3