sync: handle smartsync HTML responses better

If the server responds with an HTML page, we should show that to the
user instead of crashing with XML errors.

Bug: https://crbug.com/gerrit/15936
Change-Id: I52e6b781c3bb6a6c9f6ecbe2e0907044876cdc8d
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/337519
Reviewed-by: Raman Tenneti <rtenneti@google.com>
Tested-by: Mike Frysinger <vapier@google.com>
This commit is contained in:
Mike Frysinger 2022-05-20 23:34:44 -04:00
parent 48ea25c6a7
commit 5951e3043f

View File

@ -28,6 +28,7 @@ import time
import urllib.error import urllib.error
import urllib.parse import urllib.parse
import urllib.request import urllib.request
import xml.parsers.expat
import xmlrpc.client import xmlrpc.client
try: try:
@ -1431,11 +1432,16 @@ class PersistentTransport(xmlrpc.client.Transport):
raise raise
p, u = xmlrpc.client.getparser() p, u = xmlrpc.client.getparser()
while 1: # Response should be fairly small, so read it all at once.
data = response.read(1024) # This way we can show it to the user in case of error (e.g. HTML).
if not data: data = response.read()
break try:
p.feed(data) p.feed(data)
except xml.parsers.expat.ExpatError as e:
raise IOError(
f'Parsing the manifest failed: {e}\n'
f'Please report this to your manifest server admin.\n'
f'Here is the full response:\n{data.decode("utf-8")}')
p.close() p.close()
return u.close() return u.close()