mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 16:42:25 +00:00
refactor(logging): preserve tracebacks in remaining except blocks
Follow-up to PR #3651: - Replace logger.error with logger.exception inside except blocks so stack traces are no longer lost: - providers/transcription.py (5 occurrences) - agent/tools/mcp.py (1 occurrence) - Replace stdlib logging.getLogger with loguru logger in providers/openai_compat_provider.py for consistency.
This commit is contained in:
parent
44a341335a
commit
9a8c4da0c4
@ -616,7 +616,7 @@ async def connect_mcp_servers(
|
|||||||
try:
|
try:
|
||||||
result = await connect_single_server(name, cfg)
|
result = await connect_single_server(name, cfg)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("MCP server '{}' connection failed: {}", name, e)
|
logger.exception("MCP server '{}' connection failed: {}", name, e)
|
||||||
continue
|
continue
|
||||||
if result is not None and result[1] is not None:
|
if result is not None and result[1] is not None:
|
||||||
server_stacks[result[0]] = result[1]
|
server_stacks[result[0]] = result[1]
|
||||||
|
|||||||
@ -24,8 +24,7 @@ if os.environ.get("LANGFUSE_SECRET_KEY") and importlib.util.find_spec("langfuse"
|
|||||||
from langfuse.openai import AsyncOpenAI
|
from langfuse.openai import AsyncOpenAI
|
||||||
else:
|
else:
|
||||||
if os.environ.get("LANGFUSE_SECRET_KEY"):
|
if os.environ.get("LANGFUSE_SECRET_KEY"):
|
||||||
import logging
|
logger.warning(
|
||||||
logging.getLogger(__name__).warning(
|
|
||||||
"LANGFUSE_SECRET_KEY is set but langfuse is not installed; "
|
"LANGFUSE_SECRET_KEY is set but langfuse is not installed; "
|
||||||
"install with `pip install langfuse` to enable tracing"
|
"install with `pip install langfuse` to enable tracing"
|
||||||
)
|
)
|
||||||
|
|||||||
@ -45,7 +45,7 @@ async def _post_transcription_with_retry(
|
|||||||
try:
|
try:
|
||||||
data = path.read_bytes()
|
data = path.read_bytes()
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
logger.error("{} transcription error: cannot read audio file: {}", provider_label, e)
|
logger.exception("{} transcription error: cannot read audio file: {}", provider_label, e)
|
||||||
return ""
|
return ""
|
||||||
headers = {"Authorization": f"Bearer {api_key}"}
|
headers = {"Authorization": f"Bearer {api_key}"}
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ async def _post_transcription_with_retry(
|
|||||||
)
|
)
|
||||||
await asyncio.sleep(_BACKOFF_S[attempt])
|
await asyncio.sleep(_BACKOFF_S[attempt])
|
||||||
continue
|
continue
|
||||||
logger.error(
|
logger.exception(
|
||||||
"{} transcription error after {} attempts: {}",
|
"{} transcription error after {} attempts: {}",
|
||||||
provider_label,
|
provider_label,
|
||||||
_MAX_RETRIES + 1,
|
_MAX_RETRIES + 1,
|
||||||
@ -78,7 +78,7 @@ async def _post_transcription_with_retry(
|
|||||||
)
|
)
|
||||||
return ""
|
return ""
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("{} transcription error: {}", provider_label, e)
|
logger.exception("{} transcription error: {}", provider_label, e)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
if response.status_code in _RETRYABLE_STATUS and attempt < _MAX_RETRIES:
|
if response.status_code in _RETRYABLE_STATUS and attempt < _MAX_RETRIES:
|
||||||
@ -95,13 +95,13 @@ async def _post_transcription_with_retry(
|
|||||||
try:
|
try:
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("{} transcription error: {}", provider_label, e)
|
logger.exception("{} transcription error: {}", provider_label, e)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
payload = response.json()
|
payload = response.json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.exception(
|
||||||
"{} transcription error: malformed response body: {}",
|
"{} transcription error: malformed response body: {}",
|
||||||
provider_label,
|
provider_label,
|
||||||
e,
|
e,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user