From 412cf0aa5323ca298f6e05b52243305637fd59ab Mon Sep 17 00:00:00 2001 From: Ed Bartosh Date: Sat, 27 Oct 2012 00:52:32 +0300 Subject: [PATCH] Fixed empty response crash 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 --- gitbuildsys/oscapi.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gitbuildsys/oscapi.py b/gitbuildsys/oscapi.py index c5fcf54..4e0d2ce 100644 --- a/gitbuildsys/oscapi.py +++ b/gitbuildsys/oscapi.py @@ -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 -- 2.7.4