[PATCH] Add much better error handling.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 exception.py |   63 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/exception.py b/exception.py
index b6913a4..75aff94 100644
--- a/exception.py
+++ b/exception.py
@@ -283,6 +283,24 @@ def saveToBugzilla(anaconda, exn, dest):
     import bugzilla, xmlrpclib
     import product, rpmUtils
 
+    def withBugzillaDo(bz, fn):
+        try:
+            retval = fn(bz)
+            return retval
+        except xmlrpclib.ProtocolError, e:
+            msg = _("Your bug could not be filed due to the following error "
+                    "when communicating with bugzilla:\n\n%s" % str(e))
+        except xmlrpclib.Fault, e:
+            msg = _("Your bug could not be filed due to bad information in "
+                    "the bug fields.  This is most likely an error in "
+                    "anaconda:\n\n%s" % str(e))
+        except socket.error, e:
+            msg = _("Your bug could not be filed due to networking problems "
+                    "when communicating with bugzilla:\n\n%s" % str(e))
+
+        anaconda.intf.messageWindow(_("Unable To File Bug"), msg)
+        return None
+
     if dest[0].strip() == "" or dest[1].strip() == "" or dest[2].strip() == "":
         anaconda.intf.messageWindow(_("Invalid Bug Information"),
                                     _("Please provide a valid username, "
@@ -318,30 +336,28 @@ def saveToBugzilla(anaconda, exn, dest):
     # Are there any existing bugs with this hash value?  If so we will just
     # add this traceback to the bug report and put the reporter on the CC
     # list.  Otherwise, we need to create a new bug.
-    try:
-        buglist = bz.query({'status_whiteboard': hash})
-    except xmlrpclib.ProtocolError, e:
-        anaconda.intf.messageWindow(_("Unable To File Bug"),
-                                    _("Your bug could not be filed due to the "
-                                      "following error when communicating with "
-                                      "bugzilla:\n\n%s" % str(e)))
+    buglist = withBugzillaDo(bz, lambda b: b.query({'status_whiteboard': hash}))
+    if buglist is None:
         return False
 
-    # FIXME:  need to handle all kinds of errors here
     if len(buglist) == 0:
-        bug = bz.createbug(product=product.productName,
-                           component="anaconda",
-                           version=product.productVersion,
-                           rep_platform=rpmUtils.arch.getBaseArch(),
-                           bug_severity="medium",
-                           priority="medium",
-                           op_sys="Linux",
-                           bug_file_loc="http://";,
-                           short_desc=dest[2],
-                           comment="This bug was filed automatically by anaconda.")
+        bug = withBugzillaDo(bz, lambda b: b.createbug(product=product.productName,
+                                               component="anaconda",
+                                               version=product.productVersion,
+                                               rep_platform=rpmUtils.arch.getBaseArch(),
+                                               bug_severity="medium",
+                                               priority="medium",
+                                               op_sys="Linux",
+                                               bug_file_loc="http://";,
+                                               short_desc=dest[2],
+                                               comment="This bug was filed automatically by anaconda."))
+        if bug is None:
+            return False
+
         bug.setwhiteboard("anaconda_trace_hash:%s" % hash, which="status")
-        bz.attachfile(bug.bug_id, exn.tbFile, "Attached traceback automatically from anaconda.",
-                      contenttype="text/plain")
+        withBugzillaDo(bz, lambda b: b.attachfile(bug.bug_id, exn.tbFile,
+                                                  "Attached traceback automatically from anaconda.",
+                                                   contenttype="text/plain"))
 
         # Tell the user we created a new bug for them and that they should
         # go add a descriptive comment.
@@ -355,9 +371,10 @@ def saveToBugzilla(anaconda, exn, dest):
         sys.exit(0)
     else:
         id = buglist[0].bug_id
-        bz.attachfile(id, exn.tbFile, "Attached traceback automatically from anaconda.",
-                      contenttype="text/plain")
-        bz._updatecc(id, [dest[0]], "add")
+        withBugzillaDo(bz, lambda b: b.attachfile(id, exn.tbFile,
+                                                  "Attached traceback automatically from anaconda.",
+                                                   contenttype="text/plain"))
+        withBugzillaDo(bz, lambda b: b._updatecc(id, [dest[0]], "add"))
 
         # Tell the user which bug they've been CC'd on and that they should
         # go add a descriptive comment.
-- 
1.5.4.5

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux