Ensure we don't get stuck in formatting loops
Change-Id: I516dc2aca05823add9daf8c6d4c4af7ef7d2a313
This commit is contained in:
parent
830e4e03cb
commit
0ad2fd92ee
|
@ -98,7 +98,9 @@ class TaskFlowException(Exception):
|
|||
buf.write(self._get_message())
|
||||
active_indent = indent
|
||||
next_up = self.cause
|
||||
while next_up is not None:
|
||||
seen = []
|
||||
while next_up is not None and next_up not in seen:
|
||||
seen.append(next_up)
|
||||
buf.write(os.linesep)
|
||||
if isinstance(next_up, TaskFlowException):
|
||||
buf.write(indent_text * active_indent)
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import string
|
||||
|
||||
import six
|
||||
import testtools
|
||||
|
||||
|
@ -56,6 +58,19 @@ class TestExceptions(test.TestCase):
|
|||
self.assertIsNotNone(capture.cause)
|
||||
self.assertIsInstance(capture.cause, IOError)
|
||||
|
||||
def test_no_looping(self):
|
||||
causes = []
|
||||
for a in string.ascii_lowercase:
|
||||
try:
|
||||
cause = causes[-1]
|
||||
except IndexError:
|
||||
cause = None
|
||||
causes.append(exc.TaskFlowException('%s broken' % a, cause=cause))
|
||||
e = causes[0]
|
||||
last_e = causes[-1]
|
||||
e._cause = last_e
|
||||
self.assertIsNotNone(e.pformat())
|
||||
|
||||
def test_pformat_str(self):
|
||||
ex = None
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue