Skip to content

Commit

Permalink
Merge pull request #15 from plone/less_exception_masking
Browse files Browse the repository at this point in the history
fix(ex_handling): Don't let finally block mask ex
  • Loading branch information
tisto committed Aug 13, 2015
2 parents 109eba5 + 2c7d1b4 commit 75488ff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -4,7 +4,8 @@ Changelog
4.0.15 (unreleased)
-------------------

- Nothing changed yet.
- Prevent exception masking in finally clause of zopeApp context
[do3cc]


4.0.14 (2015-07-29)
Expand Down
33 changes: 26 additions & 7 deletions src/plone/testing/z2.py
Expand Up @@ -253,18 +253,37 @@ def zopeApp(db=None, connection=None, environ=None):
if connection is None:
connection = app._p_jar

# exceptions in finally clauses can mask exceptions
# in the preceeding code block. So we catch
# every exception and throw it instead of the exception
# in the finally clause
inner_exception = None
try:
yield app
except:
transaction.abort()
except Exception, e:
inner_exception = e
try:
transaction.abort()
except Exception, e:
inner_exception = e
raise
raise
else:
transaction.commit()
try:
transaction.commit()
except Exception, e:
inner_exception = e
finally:
app.REQUEST.close()

if closeConn:
connection.close()
try:
app.REQUEST.close()

if closeConn:
connection.close()
except:
if inner_exception:
raise inner_exception
else:
raise

# Startup layer - you probably don't want to use this one directly

Expand Down

0 comments on commit 75488ff

Please sign in to comment.