• Kirill Smelkov's avatar
    golang: Teach defer to chain exceptions (PEP 3134) even on Python2 · bb9a94c3
    Kirill Smelkov authored
    Python3 chains exceptions, so that e.g. if exc1 is raised and, while it
    was not handled, another exc2 is raised, exc2 will be linked to exc1 via
    exc2.__context__ attribute and exc1 will be included into exc2 traceback
    printout. However many projects still use Python2 and there is no
    similar chaining functionality there. This way exc1 is completely lost.
    
    Since defer code is in our hands, we can teach it to implement exception
    chaining even on Python2 by carefully analyzing what happens in
    _GoFrame.__exit__().
    
    Implementing chaining itself is relatively easy, but is only part of the
    story. Even if an exception is chained with its cause, but exception
    dump does not show the cause, the chaining will be practically useless.
    With this in mind this patches settles not only on implementing chaining
    itself, but on also giving a promise that chained cause exceptions will
    be included into traceback dumps as well.
    
    To realize this promise we adjust a...
    bb9a94c3
setup.py 10.2 KB