Skip to content

Commit

Permalink
fix(cli): handle argparse different behavior after python 3.9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Lee-W committed Sep 26, 2021
1 parent d09c085 commit ca0e4bc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down

0 comments on commit ca0e4bc

Please sign in to comment.