diff --git a/common/networking.py b/common/networking.py index 47ebe065..1afce683 100644 --- a/common/networking.py +++ b/common/networking.py @@ -8,6 +8,9 @@ from pydantic import BaseModel from typing import Optional +from common import config +from common.utils import unwrap + class TabbyRequestErrorMessage(BaseModel): """Common request error type.""" @@ -33,15 +36,18 @@ def get_generator_error(message: str, exc_info: bool = True): def handle_request_error(message: str, exc_info: bool = True): """Log a request error to the console.""" + trace = traceback.format_exc() + send_trace = unwrap(config.network_config().get("send_tracebacks"), False) + error_message = TabbyRequestErrorMessage( - message=message, trace=traceback.format_exc() + message=message, trace=trace if send_trace else None ) request_error = TabbyRequestError(error=error_message) # Log the error and provided message to the console - if error_message.trace and exc_info: - logger.error(error_message.trace) + if trace and exc_info: + logger.error(trace) logger.error(f"Sent to request: {message}") diff --git a/config_sample.yml b/config_sample.yml index 0e4b1802..3bde5eeb 100644 --- a/config_sample.yml +++ b/config_sample.yml @@ -19,6 +19,10 @@ network: # Turn on this option if you are ONLY connecting from localhost disable_auth: False + # Send tracebacks over the API to clients (default: False) + # NOTE: Only enable this for debug purposes + send_tracebacks: False + # Options for logging logging: # Enable prompt logging (default: False)