Skip to content

Commit 06ad77c

Browse files
committed
refactor(cli): do not show traceback if the raised exception is CommitizenException
1 parent 4a1e975 commit 06ad77c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

commitizen/cli.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from decli import cli
77

88
from commitizen import commands, config, out
9-
from commitizen.exceptions import CommitizenException
9+
from commitizen.exceptions import CommitizenException, ExpectedExit, NoCommandFoundError
1010

1111
logger = logging.getLogger(__name__)
1212
data = {
@@ -242,9 +242,11 @@
242242

243243

244244
def commitizen_excepthook(type, value, tracekback):
245-
original_excepthook(type, value, tracekback)
246245
if isinstance(value, CommitizenException):
246+
original_excepthook(type, value, None)
247247
sys.exit(value.exit_code)
248+
else:
249+
original_excepthook(type, value, tracekback)
248250

249251

250252
sys.excepthook = commitizen_excepthook
@@ -257,14 +259,14 @@ def main():
257259
# Show help if no arg provided
258260
if len(sys.argv) == 1:
259261
parser.print_help(sys.stderr)
260-
raise SystemExit()
262+
raise ExpectedExit()
261263

262264
# This is for the command required constraint in 2.0
263265
try:
264266
args = parser.parse_args()
265267
except TypeError:
266268
out.error("Command is required")
267-
raise SystemExit()
269+
raise NoCommandFoundError()
268270

269271
if args.name:
270272
conf.update({"name": args.name})
@@ -297,4 +299,4 @@ def main():
297299
args.func(conf, vars(args))()
298300
except AttributeError:
299301
out.error("Command is required")
300-
raise SystemExit()
302+
raise NoCommandFoundError()

0 commit comments

Comments
 (0)