mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added 'append' option to exceptionLogged to print out before or after stack trace
This commit is contained in:
parent
d7b0ba8510
commit
a0307f90a0
@ -191,7 +191,7 @@ class DoCollectionManager:
|
|||||||
else:
|
else:
|
||||||
self.notify.warning('handleSetLocation: object %s not present' % self.getMsgChannel())
|
self.notify.warning('handleSetLocation: object %s not present' % self.getMsgChannel())
|
||||||
|
|
||||||
@exceptionLogged
|
@exceptionLogged()
|
||||||
def storeObjectLocation(self, object, parentId, zoneId):
|
def storeObjectLocation(self, object, parentId, zoneId):
|
||||||
oldParentId = object.parentId
|
oldParentId = object.parentId
|
||||||
oldZoneId = object.zoneId
|
oldZoneId = object.zoneId
|
||||||
|
@ -2491,30 +2491,39 @@ def superFlattenShip(ship):
|
|||||||
#PHASE 5: flatten strong!
|
#PHASE 5: flatten strong!
|
||||||
return ship.flattenStrong()
|
return ship.flattenStrong()
|
||||||
|
|
||||||
def exceptionLogged(f):
|
def exceptionLogged(append=True):
|
||||||
"""decorator that appends the function name and all arguments to the
|
"""decorator that outputs the function name and all arguments
|
||||||
__str__ output of the exception if an exception passes back through
|
if an exception passes back through the stack frame
|
||||||
the stack frame
|
if append is true, string is appended to the __str__ output of
|
||||||
|
the exception. if append is false, string is printed to the log
|
||||||
|
directly. If the output will take up many lines, it's recommended
|
||||||
|
to set append to False so that the exception stack is not hidden
|
||||||
|
by the output of this decorator.
|
||||||
"""
|
"""
|
||||||
def _exceptionLogged(*args, **kArgs):
|
def _decoratorFunc(f, append=append):
|
||||||
try:
|
def _exceptionLogged(*args, **kArgs):
|
||||||
return f(*args, **kArgs)
|
|
||||||
except Exception, e:
|
|
||||||
try:
|
try:
|
||||||
s = '\nSTACK UNWIND: %s(' % f.func_name
|
return f(*args, **kArgs)
|
||||||
for arg in args:
|
except Exception, e:
|
||||||
s += '%s, ' % arg
|
try:
|
||||||
for key, value in kArgs.items():
|
s = 'STACK UNWIND: %s(' % f.func_name
|
||||||
s += '%s=%s, ' % (key, value)
|
for arg in args:
|
||||||
if len(args) or len(kArgs):
|
s += '%s, ' % arg
|
||||||
s = s[:-2]
|
for key, value in kArgs.items():
|
||||||
s += ')'
|
s += '%s=%s, ' % (key, value)
|
||||||
appendStr(e, s)
|
if len(args) or len(kArgs):
|
||||||
except:
|
s = s[:-2]
|
||||||
print 'exceptionLogged(%s): ERROR IN PRINTING' % f.func_name
|
s += ')'
|
||||||
raise
|
if append:
|
||||||
_exceptionLogged.__doc__ = f.__doc__
|
appendStr(e, '\n%s' % s)
|
||||||
return _exceptionLogged
|
else:
|
||||||
|
print s
|
||||||
|
except:
|
||||||
|
print 'exceptionLogged(%s): ERROR IN PRINTING' % f.func_name
|
||||||
|
raise
|
||||||
|
_exceptionLogged.__doc__ = f.__doc__
|
||||||
|
return _exceptionLogged
|
||||||
|
return _decoratorFunc
|
||||||
|
|
||||||
# class 'decorator' that records the stack at the time of creation
|
# class 'decorator' that records the stack at the time of creation
|
||||||
# be careful with this, it creates a StackTrace, and that can take a
|
# be careful with this, it creates a StackTrace, and that can take a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user