Networking: Gate sending tracebacks over the API
It's possible that tracebacks can give too much info about a system when sent over the API. Gate this under a flag to send them only when debugging since this feature is still useful. Signed-off-by: kingbri <bdashore3@proton.me>
This commit is contained in:
parent
ddad422d8b
commit
6019c93637
2 changed files with 13 additions and 3 deletions
|
|
@ -8,6 +8,9 @@ from loguru import logger
|
|||
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}")
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue