Report encoding errors nicely.

This commit is contained in:
Darko Poljak 2018-09-04 08:27:20 +02:00
parent b9ddbb1aa0
commit 3782656569

View file

@ -100,6 +100,7 @@ class CdistEntityError(Error):
for name, path in stdpaths:
if name not in result:
result[name] = []
try:
if os.path.exists(path) and os.path.getsize(path) > 0:
output = []
label_begin = name + ":" + header_name
@ -111,6 +112,11 @@ class CdistEntityError(Error):
output.append(fd.read())
output.append('\n')
result[name].append(''.join(output))
except UnicodeError as ue:
result[name].append(('Cannot output {}:{} due to: {}.\n'
'You can try to read the error file "{}"'
' yourself.').format(
name, header_name, ue, path))
return result
def _stderr(self):