Report encoding errors nicely.
This commit is contained in:
parent
b9ddbb1aa0
commit
3782656569
1 changed files with 17 additions and 11 deletions
|
@ -100,17 +100,23 @@ class CdistEntityError(Error):
|
||||||
for name, path in stdpaths:
|
for name, path in stdpaths:
|
||||||
if name not in result:
|
if name not in result:
|
||||||
result[name] = []
|
result[name] = []
|
||||||
if os.path.exists(path) and os.path.getsize(path) > 0:
|
try:
|
||||||
output = []
|
if os.path.exists(path) and os.path.getsize(path) > 0:
|
||||||
label_begin = name + ":" + header_name
|
output = []
|
||||||
output.append(label_begin)
|
label_begin = name + ":" + header_name
|
||||||
output.append('\n')
|
output.append(label_begin)
|
||||||
output.append('-' * len(label_begin))
|
output.append('\n')
|
||||||
output.append('\n')
|
output.append('-' * len(label_begin))
|
||||||
with open(path, 'r') as fd:
|
output.append('\n')
|
||||||
output.append(fd.read())
|
with open(path, 'r') as fd:
|
||||||
output.append('\n')
|
output.append(fd.read())
|
||||||
result[name].append(''.join(output))
|
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
|
return result
|
||||||
|
|
||||||
def _stderr(self):
|
def _stderr(self):
|
||||||
|
|
Loading…
Reference in a new issue