From 2a398a3543bfa1824a6c164f8ba07d80f37520bb Mon Sep 17 00:00:00 2001 From: leunga1000 <24807638+leunga1000@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:04:00 +0100 Subject: [PATCH] Adding traceback info to the default error log (#176) * Update socketify.py * Update socketify.py --- src/socketify/socketify.py | 49 +++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/src/socketify/socketify.py b/src/socketify/socketify.py index 2c74e1c..6ddc68e 100644 --- a/src/socketify/socketify.py +++ b/src/socketify/socketify.py @@ -8,6 +8,7 @@ import uuid from urllib.parse import parse_qs, quote_plus, unquote_plus import logging +import traceback from .native import ffi, lib from .loop import Loop @@ -33,7 +34,7 @@ def uws_missing_server_name(hostname, hostname_length, user_data): handler(data) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception:\n %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -67,7 +68,7 @@ async def wrapper(app, instances, handler, ws): if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -89,7 +90,7 @@ def uws_websocket_drain_handler_with_extension(ws, user_data): handler(ws) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -107,7 +108,7 @@ def uws_websocket_drain_handler(ws, user_data): handler(ws) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -189,7 +190,7 @@ async def wrapper( if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -232,7 +233,7 @@ def uws_websocket_subscription_handler( ) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -279,7 +280,7 @@ def uws_websocket_subscription_handler_with_extension( ) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -312,7 +313,7 @@ async def wrapper(app, instances, handler, ws): if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -335,7 +336,7 @@ def uws_websocket_open_handler_with_extension(ws, user_data): handler(ws) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -354,7 +355,7 @@ def uws_websocket_open_handler(ws, user_data): handler(ws) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -396,7 +397,7 @@ async def wrapper(app, instances, handler, ws, data): if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -430,7 +431,7 @@ def uws_websocket_message_handler_with_extension( except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -458,7 +459,7 @@ def uws_websocket_message_handler(ws, message, length, opcode, user_data): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -497,7 +498,7 @@ async def wrapper(app, instances, handler, ws, data): if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -524,7 +525,7 @@ def uws_websocket_pong_handler_with_extension(ws, message, length, user_data): handler(ws, data) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -547,7 +548,7 @@ def uws_websocket_pong_handler(ws, message, length, user_data): handler(ws, data) except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -587,7 +588,7 @@ async def wrapper(app, instances, handler, ws, data): if dispose: app._ws_factory.dispose(instances) logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -616,7 +617,7 @@ def uws_websocket_ping_handler_with_extension(ws, message, length, user_data): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -641,7 +642,7 @@ def uws_websocket_ping_handler(ws, message, length, user_data): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -691,7 +692,7 @@ async def wrapper(app, instances, handler, ws, code, data, dispose): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -737,7 +738,7 @@ async def wrapper(app, handler, ws, code, data): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -779,7 +780,7 @@ async def wrapper(app, handler, ws, code, data): except Exception as err: logging.error( - "Uncaught Exception: %s" % str(err) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention @@ -3420,7 +3421,7 @@ def trigger_error(self, error, response, request): if self.error_handler is None: try: logging.error( - "Uncaught Exception: %s" % str(error) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention response.write_status(500).end("Internal Error") finally: @@ -3437,7 +3438,7 @@ def trigger_error(self, error, response, request): try: # Error handler got an error :D logging.error( - "Uncaught Exception: %s" % str(error) + "Uncaught Exception: %s" % traceback.format_exc() ) # just log in console the error to call attention response.write_status(500).end("Internal Error") finally: