Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/extensions/utils.py

Issue 29370859: Issue 4767 - Improve error reporting in update_update_manifests (Closed)
Patch Set: For comment 16 Created Jan. 15, 2017, 7:32 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/extensions/utils.py
===================================================================
--- a/sitescripts/extensions/utils.py
+++ b/sitescripts/extensions/utils.py
@@ -26,6 +26,7 @@
from ConfigParser import SafeConfigParser, NoOptionError
from StringIO import StringIO
from sitescripts.utils import get_config
+from xml.parsers.expat import ExpatError
PACKAGE_SUFFIXES = {
'gecko': '.xpi',
@@ -250,17 +251,31 @@
try:
return urllib.urlopen(url)
except IOError as e:
- error = e
+ error = Exception('Error {0} while opening {1} url'
+ .format(e, url))
time.sleep(5)
raise error
+def _parseXMLDocument(url, attempts=2):
+ for i in range(attempts):
+ page = _urlopen(url)
+ content = page.read()
+ page.close()
Sebastian Noack 2017/01/17 09:33:32 The close() should have gone into a finally block,
Sebastian Noack 2017/01/17 10:16:56 Yes, in Python 2, the repsonse object returned by
Sebastian Noack 2017/01/17 10:20:15 Well, alternatively you could use try-finally. But
Vasily Kuznetsov 2017/01/17 10:30:34 Yeah, with is nicer, especially having Python 3 in
+ try:
+ return dom.parseString(content)
+ except ExpatError as err:
+ exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}'
+ .format(err, content, url))
+ raise exception
+
+
def _getMozillaDownloadLink(galleryID):
"""
gets download link for a Gecko add-on from the Mozilla Addons site
"""
url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _urlencode(galleryID)
- document = dom.parse(_urlopen(url))
+ document = _parseXMLDocument(url)
linkTags = document.getElementsByTagName('install')
linkTag = linkTags[0] if len(linkTags) > 0 else None
versionTags = document.getElementsByTagName('version')
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld