Skip to content

Commit

Permalink
Merge pull request #41 from radiasoft/issue/29_py3_pkdexc
Browse files Browse the repository at this point in the history
Fix #29 correct ordering of stacks in py3
  • Loading branch information
Rob Nagler authored Aug 26, 2019
2 parents 582f61b + 80f90cf commit fad4c1c
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions pykern/pkdebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,21 @@ def pkdexc():
try:
e = sys.exc_info()
# py2 doesn't cascade exceptions
stack = traceback.format_stack()[:-2]
if hasattr(traceback, 'TracebackException'):
stack += traceback.format_exception(*e)
return ''.join(
traceback.format_exception(*e) \
+ ['\nException was printed at:\n\n'] \
+ traceback.format_exception_only(e[0], e[1]) \
+ traceback.format_stack()[:-2],
)

else:
stack += traceback.format_tb(e[2])
return ''.join(traceback.format_exception_only(e[0], e[1]) + stack)
return ''.join(
traceback.format_exception_only(e[0], e[1]) \
+ traceback.format_stack()[:-2] \
+ traceback.format_tb(e[2]),
)

except Exception as e:
return 'pykern.pkdebug.pkdexc: unable to retrieve exception info'

Expand Down

0 comments on commit fad4c1c

Please sign in to comment.