Ensure we don't get stuck in formatting loops
Change-Id: I516dc2aca05823add9daf8c6d4c4af7ef7d2a313
This commit is contained in:
@@ -98,7 +98,9 @@ class TaskFlowException(Exception):
|
|||||||
buf.write(self._get_message())
|
buf.write(self._get_message())
|
||||||
active_indent = indent
|
active_indent = indent
|
||||||
next_up = self.cause
|
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)
|
buf.write(os.linesep)
|
||||||
if isinstance(next_up, TaskFlowException):
|
if isinstance(next_up, TaskFlowException):
|
||||||
buf.write(indent_text * active_indent)
|
buf.write(indent_text * active_indent)
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import string
|
||||||
|
|
||||||
import six
|
import six
|
||||||
import testtools
|
import testtools
|
||||||
|
|
||||||
@@ -56,6 +58,19 @@ class TestExceptions(test.TestCase):
|
|||||||
self.assertIsNotNone(capture.cause)
|
self.assertIsNotNone(capture.cause)
|
||||||
self.assertIsInstance(capture.cause, IOError)
|
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):
|
def test_pformat_str(self):
|
||||||
ex = None
|
ex = None
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user