summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-04-02 12:51:34 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-04-03 13:31:10 +0200
commitdfde363aa63ad3e7967da49f4ab599399b89e7f8 (patch)
tree051f1f1d1e3c8e07ae12af2bfb35174be18f1201 /src/ogRest.py
parentc5ccc3c7e201beccf8eb3d329e478bb33b34d43e (diff)
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.
Diffstat (limited to 'src/ogRest.py')
-rw-r--r--src/ogRest.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/ogRest.py b/src/ogRest.py
index c7bdcdb..5d6c746 100644
--- a/src/ogRest.py
+++ b/src/ogRest.py
@@ -19,6 +19,7 @@ import logging
from logging.handlers import SysLogHandler
from src.restRequest import *
+from src.log import OgError
class ThreadState(Enum):
@@ -263,13 +264,13 @@ class ogRest():
from src.windows.ogOperations import OgWindowsOperations
self.operations = OgWindowsOperations()
else:
- raise ValueError(f'Ogrest mode \'{self.mode}\'not supported')
+ raise OgError(f'Ogrest mode \'{self.mode}\'not supported')
def send_internal_server_error(self, client, exc=None):
- if isinstance(exc, AssertionError):
- logging.exception(exc)
- else:
+ if isinstance(exc, OgError):
logging.error(exc)
+ else:
+ logging.exception(exc)
response = restResponse(ogResponses.INTERNAL_ERR, seq=client.seq)
client.send(response.get())
self.state = ThreadState.IDLE