fix(approval,mcp): log silent exception handlers, narrow OAuth catches, close server on error

Three silent `except Exception` blocks in approval.py (lines 345, 387, 469) return
fallback values with zero logging — making it impossible to debug callback failures,
allowlist load errors, or config read issues.  Add logger.warning/error calls that
match the pattern already used by save_permanent_allowlist() and _smart_approve()
in the same file.

In mcp_oauth.py, narrow the overly-broad `except Exception` in get_tokens() and
get_client_info() to the specific exceptions Pydantic's model_validate() can raise
(ValueError, TypeError, KeyError), and include the exception message in the warning.
Also wrap the _wait_for_callback() polling loop in try/finally so the HTTPServer is
always closed — previously an asyncio.CancelledError or any exception in the loop
would leak the server socket.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
aaronagent 2026-04-10 11:42:40 +08:00 committed by Teknium
parent 738f0bac13
commit 94f5979cc2
2 changed files with 18 additions and 14 deletions

View file

@ -342,7 +342,8 @@ def load_permanent_allowlist() -> set:
if patterns:
load_permanent(patterns)
return patterns
except Exception:
except Exception as e:
logger.warning("Failed to load permanent allowlist: %s", e)
return set()
@ -384,7 +385,8 @@ def prompt_dangerous_approval(command: str, description: str,
try:
return approval_callback(command, description,
allow_permanent=allow_permanent)
except Exception:
except Exception as e:
logger.error("Approval callback failed: %s", e, exc_info=True)
return "deny"
os.environ["HERMES_SPINNER_PAUSE"] = "1"
@ -466,7 +468,8 @@ def _get_approval_config() -> dict:
from hermes_cli.config import load_config
config = load_config()
return config.get("approvals", {}) or {}
except Exception:
except Exception as e:
logger.warning("Failed to load approval config: %s", e)
return {}