Merge "Move the _pformat() method to be a classmethod"

This commit is contained in:
Jenkins 2014-12-03 00:29:09 +00:00 committed by Gerrit Code Review
commit f4bf736ca6

View File

@ -46,21 +46,26 @@ class TaskFlowException(Exception):
"""Pretty formats a taskflow exception + any connected causes.""" """Pretty formats a taskflow exception + any connected causes."""
if indent < 0: if indent < 0:
raise ValueError("indent must be greater than or equal to zero") raise ValueError("indent must be greater than or equal to zero")
return "\n".join(self._pformat(self, [], 0,
indent=indent, indent_text=indent_text))
def _format(excp, indent_by): @classmethod
lines = [] def _pformat(cls, excp, lines, current_indent, indent=2, indent_text=" "):
for line in traceback.format_exception_only(type(excp), excp): line_prefix = indent_text * current_indent
# We'll add our own newlines on at the end of formatting. for line in traceback.format_exception_only(type(excp), excp):
if line.endswith("\n"): # We'll add our own newlines on at the end of formatting.
line = line[0:-1] if line.endswith("\n"):
lines.append((indent_text * indent_by) + line) line = line[0:-1]
try: lines.append(line_prefix + line)
lines.extend(_format(excp.cause, indent_by + indent)) try:
except AttributeError: cause = excp.cause
pass except AttributeError:
return lines pass
else:
return "\n".join(_format(self, 0)) if cause is not None:
cls._pformat(cause, lines, current_indent + indent,
indent=indent, indent_text=indent_text)
return lines
# Errors related to storage or operations on storage units. # Errors related to storage or operations on storage units.