From dfde363aa63ad3e7967da49f4ab599399b89e7f8 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 2 Apr 2024 12:51:34 +0200 Subject: src: log backtrace in unhandled error cases Log an error message in known error cases and log a backtrace otherwise. Define a new error type OgError to be used in all the 'raise' blocks to define the error message to log. The exception propagates until it reaches send_internal_server_error() where the exception type is checked. If the type is OgError we log the exception message. Logs the backtrace for other types. The initial error implementation printed a backtrace everytime an error ocurred. The next iteration changed it to only print a backtrace in a very particular case but ended up omiting too much information such as syntax errors or unknown error context. The actual implementation only logs the cases we already cover in the codebase and logs a bracktrace in the others, enabling a better debugging experience. --- ogclient | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ogclient') diff --git a/ogclient b/ogclient index a83b9ed..b302641 100755 --- a/ogclient +++ b/ogclient @@ -20,7 +20,7 @@ except ImportError: from src.ogClient import * -from src.log import configure_logging +from src.log import * def send_event_dgram(msg, ip='127.0.0.1', port=55885): @@ -92,7 +92,7 @@ def main(): client = ogClient(config=CONFIG) client.connect() client.run() - except Exception as e: + except OgError as e: logging.critical(e) if __name__ == "__main__": -- cgit v1.2.3-18-g5258