Fix mechanism catching amp errors
This commit is contained in:
parent
ae979e852d
commit
a7694fb6e9
1 changed files with 13 additions and 11 deletions
|
|
@ -83,6 +83,14 @@ def loads(data):
|
||||||
return pickle.loads(to_str(data))
|
return pickle.loads(to_str(data))
|
||||||
|
|
||||||
|
|
||||||
|
def _get_logger():
|
||||||
|
"Delay import of logger until absolutely necessary"
|
||||||
|
global _LOGGER
|
||||||
|
if not _LOGGER:
|
||||||
|
from evennia.utils import logger as _LOGGER
|
||||||
|
return _LOGGER
|
||||||
|
|
||||||
|
|
||||||
@wraps
|
@wraps
|
||||||
def catch_traceback(func):
|
def catch_traceback(func):
|
||||||
"Helper decorator"
|
"Helper decorator"
|
||||||
|
|
@ -90,10 +98,7 @@ def catch_traceback(func):
|
||||||
try:
|
try:
|
||||||
func(*args, **kwargs)
|
func(*args, **kwargs)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
global _LOGGER
|
_get_logger().log_trace()
|
||||||
if not _LOGGER:
|
|
||||||
from evennia.utils import logger as _LOGGER
|
|
||||||
_LOGGER.log_trace()
|
|
||||||
raise # make sure the error is visible on the other side of the connection too
|
raise # make sure the error is visible on the other side of the connection too
|
||||||
print(err)
|
print(err)
|
||||||
return decorator
|
return decorator
|
||||||
|
|
@ -282,7 +287,7 @@ class AMPMultiConnectionProtocol(amp.AMP):
|
||||||
try:
|
try:
|
||||||
super(AMPMultiConnectionProtocol, self).dataReceived(data)
|
super(AMPMultiConnectionProtocol, self).dataReceived(data)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.trace("Discarded incoming partial data: {}".format(to_str(data)))
|
_get_logger().log_trace("Discarded incoming partial data: {}".format(to_str(data)))
|
||||||
elif self.multibatches:
|
elif self.multibatches:
|
||||||
# invalid AMP, but we have a pending multi-batch that is not yet complete
|
# invalid AMP, but we have a pending multi-batch that is not yet complete
|
||||||
if data[-2:] == NULNUL:
|
if data[-2:] == NULNUL:
|
||||||
|
|
@ -291,7 +296,7 @@ class AMPMultiConnectionProtocol(amp.AMP):
|
||||||
try:
|
try:
|
||||||
super(AMPMultiConnectionProtocol, self).dataReceived(data)
|
super(AMPMultiConnectionProtocol, self).dataReceived(data)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
_LOGGER.trace("Discarded incoming multi-batch data:".format(to_str(data)))
|
_get_logger().log_trace("Discarded incoming multi-batch data:".format(to_str(data)))
|
||||||
else:
|
else:
|
||||||
# not an AMP communication, return warning
|
# not an AMP communication, return warning
|
||||||
self.transport.write(_HTTP_WARNING)
|
self.transport.write(_HTTP_WARNING)
|
||||||
|
|
@ -345,11 +350,8 @@ class AMPMultiConnectionProtocol(amp.AMP):
|
||||||
info (str): Error string.
|
info (str): Error string.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
global _LOGGER
|
|
||||||
if not _LOGGER:
|
|
||||||
from evennia.utils import logger as _LOGGER
|
|
||||||
e.trap(Exception)
|
e.trap(Exception)
|
||||||
_LOGGER.log_err("AMP Error for %(info)s: %(e)s" % {'info': info,
|
_get_logger().log_err("AMP Error for %(info)s: %(e)s" % {'info': info,
|
||||||
'e': e.getErrorMessage()})
|
'e': e.getErrorMessage()})
|
||||||
|
|
||||||
def data_in(self, packed_data):
|
def data_in(self, packed_data):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue