From ca0e4bcd0a2b3d6dbf9beeb9334c823b4e5cd9fc Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 26 Sep 2021 16:09:01 +0800 Subject: [PATCH] fix(cli): handle argparse different behavior after python 3.9 argparse raises TypeError when non exist command is provided on Python < 3.9 but raise SystemExit with exit code == 2 on Python 3.9 this error does not break anything obviously from the user perspective, but will break our existing test 429 --- commitizen/cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index a5c336f9fd..2fb482094b 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -286,8 +286,13 @@ def main(): # This is for the command required constraint in 2.0 try: args = parser.parse_args() - except TypeError: - raise NoCommandFoundError() + except (TypeError, SystemExit) as e: + # https://github.com/commitizen-tools/commitizen/issues/429 + # argparse raises TypeError when non exist command is provided on Python < 3.9 + # but raise SystemExit with exit code == 2 on Python 3.9 + if isinstance(e, TypeError) or (isinstance(e, SystemExit) and e.code == 2): + raise NoCommandFoundError() + raise e if args.name: conf.update({"name": args.name})