• Kirill Smelkov's avatar
    golang: Fix defer exception chaining in the presence of subchains · 1477dd02
    Kirill Smelkov authored
    A deferred function can raise exception and this exception itself can
    have .__context__ - consider for example if B1 is raised and its chain
    is B1->B2->B3. Before calling that deferred function, we save
    then-current exception A1 into GoFrame.exc_ctx and link-to .exc_ctx after
    the call. We were previously trying to link-to .exc_ctx from raised
    exception itself - i.e. B1 in the above example which is not correct:
    B1 was raised while B2 was being raised ... etc and it was B3 who was
    raised after A1. The consequence was that A1 was list, since B1 already
    had non-empty .__context__
    
    -> Fix it by linking-to A1 from B3, not from B1. In other words by
    linking-to .exc_ctx chain from tail of exception chain of raised
    exception.
    
    We can be sure that updated test is correct because it passes under
    Python3 where exception chaining is implemented natively.
    
    Fixes: bb9a94c3 (golang: Teach defer to chain exceptions (PEP 3134) even on Python2)
    1477dd02
golang_test.py 44 KB