Fixed empty response crash
authorEd Bartosh <eduard.bartosh@intel.com>
Fri, 26 Oct 2012 21:52:32 +0000 (00:52 +0300)
committerEd Bartosh <eduard.bartosh@intel.com>
Fri, 26 Oct 2012 22:18:08 +0000 (01:18 +0300)
Sometimemes OBS returns empty response without raising any exceptions.
remove_files API tries to parse this response as xml and crashing if
it's empty. It happens not very often, so trying 3 times to get
something parseable should work around this OBS bug.

Fixes: #495
Change-Id: Ica6c4fc3acf01f4c698651606dd1472ef888adf7
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
gitbuildsys/oscapi.py

index c5fcf54cad820bcfea0f6286352f2559c2ac1dcd..4e0d2ce4ab8c6c228f080b1e51abbb81cc116272 100644 (file)
@@ -255,14 +255,22 @@ class OSC(object):
         """
         if not fnames:
             url = core.makeurl(self.apiurl, ['source', prj, pkg])
-            try:
-                response = self.core_http(core.http_GET, url).read()
-            except OSCError, err:
-                raise ObsError("can't get list of sources from"\
-                               " %s/%s: %s" % (prj, pkg, err))
+            for i in (1, 2, 3):
+                try:
+                    response = self.core_http(core.http_GET, url).read()
+                    entries = core.ET.fromstring(response)
+                   break
+                except OSCError, err:
+                    raise ObsError("can't get list of sources from"\
+                                   " %s/%s: %s" % (prj, pkg, err))
+                except core.ET.ParseError, err:
+                    if i == 3:
+                        raise ObsError("Error parsing OBS response: %s" \
+                                       % str(err))
+                    continue
+
+            fnames = [entry.get('name') for entry in entries]
 
-            fnames = [entry.get('name') for entry in \
-                                            core.ET.fromstring(response)]
         for fname in fnames:
             if fname is None:
                 continue