Skip to content

Commit debb953

Browse files
authored
Merge pull request #6 from /issues/1-panic-logs-none
`panic()` should only log on secondary exceptions (fixes #1)
2 parents 401a1ab + 1e5becb commit debb953

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/bd2k/util/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __enter__( self ):
3131
self.exc_info = sys.exc_info( )
3232

3333
def __exit__( self, *exc_info ):
34-
if self.log is not None:
34+
if self.log is not None and exc_info and exc_info[0]:
3535
self.log.warn( "Exception during panic", exc_info=exc_info )
3636
exc_type, exc_value, traceback = self.exc_info
3737
raise exc_type, exc_value, traceback

src/bd2k/util/test/test_panic.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def test_panic( self ):
2121
except:
2222
self.__assert_raised_exception_is_primary( )
2323

24+
def test_panic_with_secondary( self ):
25+
try:
26+
self.try_and_panic_with_secondary( )
27+
except:
28+
self.__assert_raised_exception_is_primary( )
29+
2430
def try_and_panic_by_hand( self ):
2531
try:
2632
self.line_of_primary_exc = inspect.currentframe( ).f_lineno + 1
@@ -34,6 +40,14 @@ def try_and_panic_by_hand( self ):
3440
raise exc_type, exc_value, exc_traceback
3541

3642
def try_and_panic( self ):
43+
try:
44+
self.line_of_primary_exc = inspect.currentframe( ).f_lineno + 1
45+
raise ValueError( "primary" )
46+
except:
47+
with panic( log ):
48+
pass
49+
50+
def try_and_panic_with_secondary( self ):
3751
try:
3852
self.line_of_primary_exc = inspect.currentframe( ).f_lineno + 1
3953
raise ValueError( "primary" )

0 commit comments

Comments
 (0)