fix(proxy/hooks): drop literal 'None' from raise_rate_limit_error detail

The v1 parallel_request_limiter's raise_rate_limit_error helper has a
long-standing bug: it computes a None-guarded 'error_message' string but
then ignores it and emits an f-string that interpolates the raw
'additional_details' arg. Callers that pass no argument get
'Max parallel request limit reached None' as the user-facing detail.

This commit:
* wires error_message into the detail kwarg so the None-guard actually
  applies and operators see a clean message;
* changes the return-type annotation from ProxyRateLimitError to NoReturn
  (the function always raises) so type-checkers know callers after this
  invocation are unreachable.

Greptile P1 + P2 review feedback on PR #27687.

LIT-2968

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-05-11 23:22:26 +00:00
parent 4e5abe1710
commit 2074848185
No known key found for this signature in database

View file

@ -126,11 +126,16 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger):
"""
Raise a 429 with a retry-after header for litellm-proxy parallel-request limits.
Raises a :class:`ProxyRateLimitError`, which is both a
Always raises :class:`ProxyRateLimitError` — never returns. Annotated
``NoReturn`` so type-checkers know callers after this invocation are
unreachable. The raised exception is both a
:class:`litellm.RateLimitError` (so callers can catch by category) and a
:class:`fastapi.HTTPException` (so the FastAPI dispatcher serializes it
correctly with status 429 and the supplied headers).
"""
# additional_details is optional; build the detail with a None-guard
# so callers that pass nothing don't get the literal string "None"
# interpolated into the error message.
error_message = "Max parallel request limit reached"
if additional_details is not None:
error_message = error_message + " " + additional_details