From ba86509c1d8700a50fe14e9d931ee57261306c5f Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 21 Jan 2022 12:15:34 -0800 Subject: [PATCH] simplify OSError exception handling --- jc/cli.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/jc/cli.py b/jc/cli.py index df496553..9798f7a8 100644 --- a/jc/cli.py +++ b/jc/cli.py @@ -470,18 +470,12 @@ def main(): if magic_stderr: print(magic_stderr[:-1], file=sys.stderr) - except FileNotFoundError: + except OSError as e: if debug: raise - utils.error_message([f'"{run_command_str}" command could not be found. For details use the -d or -dd option.']) - sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) - - except OSError: - if debug: - raise - - utils.error_message([f'"{run_command_str}" command could not be run due to too many open files. For details use the -d or -dd option.']) + error_msg = os.strerror(e.errno) + utils.error_message([f'"{run_command_str}" command could not be run: {error_msg}. For details use the -d or -dd option.']) sys.exit(combined_exit_code(magic_exit_code, JC_ERROR_EXIT)) except Exception: