Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
1.2.2
Description
except Exception as e: reportError(traceback.format_exc(e)) fail(tup) except Exception as e: reportError(traceback.format_exc(e))
The method signature for traceback.format_exc is (limit=None, chain=True). Where limit is an int and chain a bool. See documentation for python2.7 and 3:
https://docs.python.org/2.7/library/traceback.html
https://docs.python.org/3/library/traceback.html
Passing an Exception object results in the exception handling code throwing an exception itself and crashing out as a result:
During handling of the above exception, another exception occurred: Traceback (most recent call last): File "word_joiner.py", line 20, in <module> WordJoiner().run() File "/tmp/be86d36d-d293-4694-a8f0-0f018e540936/supervisor/stormdist/test-1-1532824220/resources/storm.py", line 200, in run reportError(traceback.format_exc(e)) File "/usr/lib/python3.4/traceback.py", line 256, in format_exc return "".join(format_exception(*sys.exc_info(), limit=limit, chain=chain)) File "/usr/lib/python3.4/traceback.py", line 181, in format_exception return list(_format_exception_iter(etype, value, tb, limit, chain)) File "/usr/lib/python3.4/traceback.py", line 153, in _format_exception_iter yield from _format_list_iter(_extract_tb_iter(tb, limit=limit)) File "/usr/lib/python3.4/traceback.py", line 18, in _format_list_iter for filename, lineno, name, line in extracted_list: File "/usr/lib/python3.4/traceback.py", line 58, in _extract_tb_or_stack_iter while curr is not None and (limit is None or n < limit): TypeError: unorderable types: int() < TypeError()
The solution in this case is to simply not pass any arguments to traceback.format_exc. It will automatically fetch the context of the catch block it resides in and gracefully return the traceback as a string, which is what storm.py is expecting.