Skip to content

Commit 5c48070

Browse files
committed
Enclose bz assignment with try-except
Exceptions may be thrown when creating the instance of `bugzilla.Bugzilla`. It is necessary to catch them to avoid unnecessary interruption of while-loop.
1 parent c76a180 commit 5c48070

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

bugzilla/_mi.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def _print_message_patched(self, message, file=None):
111111
swrite(FLAG_TAIL_ARGINF)
112112
sflush()
113113

114+
114115
def exit_patched(self, status=0, message=None):
115116
""" A patch on `argparse.ArgumentParser`
116117
@@ -124,6 +125,7 @@ def exit_patched(self, status=0, message=None):
124125
self._print_message(emsg)
125126
raise InterruptLoop
126127

128+
127129
class Bugzilla_patched(bugzilla.Bugzilla):
128130
""" Patch `bugzilla.Bugzilla` to fit MI
129131
@@ -209,6 +211,7 @@ def setup_logging():
209211
datefmt="%y.%m.%d %H:%M:%S"))
210212
log.addHandler(handler)
211213

214+
212215
def level_logging(debug, verbose):
213216
""" Change log level on the fly
214217
"""
@@ -405,6 +408,7 @@ def _process_attachment_data(_attlist):
405408
swrite(FLAG_TAIL_ATTACH)
406409
sflush()
407410

411+
408412
def _do_set_attach(bz, opt, parser):
409413
""" (Patched version)
410414
Replace original print statement;
@@ -551,11 +555,20 @@ def _main(unittest_bz_instance):
551555
log.debug("Bugzilla module: %s", bugzilla)
552556
NewAct = NewOpt.command
553557

554-
if unittest_bz_instance:
555-
bz = unittest_bz_instance
556-
else:
557-
bz = _make_bz_instance(NewOpt, force_new=bz_REFRESH)
558-
bz_REFRESH = False
558+
try:
559+
if unittest_bz_instance:
560+
bz = unittest_bz_instance
561+
else:
562+
bz = _make_bz_instance(NewOpt, force_new=bz_REFRESH)
563+
bz_REFRESH = False
564+
except Exception as E:
565+
swrite(FLAG_HEAD_EXCEPT)
566+
swrite("CANNOT create the instance of `bugzilla.Bugzilla` ")
567+
swrite("with args ` %s ` because of " % NewCmd)
568+
swrite("%s: %s" %(E.__class__.__name__,str(E)))
569+
swrite(FLAG_TAIL_EXCEPT)
570+
sflush()
571+
continue
559572

560573
try:
561574
# Handle login options
@@ -629,6 +642,7 @@ def _main(unittest_bz_instance):
629642
bz_REFRESH = True
630643
continue
631644

645+
632646
def main(unittest_bz_instance=None):
633647
""" (Patched version)
634648
"""

0 commit comments

Comments
 (0)