fix(proxy): populate Exception.args so str(ProxyException) returns message (LIT-3094)#29015
Conversation
…ssage Adds super().__init__(self.message) to ProxyException.__init__ so that str(exc) returns the stored message instead of empty string. Fixes LIT-3094.
|
|
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — a minimal, well-tested one-line fix with no side effects on existing behaviour. The change is a single No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Adds super().__init__(self.message) in ProxyException.__init__ so Exception.args is populated and str(exc) returns the human-readable message instead of an empty string. |
| tests/test_litellm/proxy/test_proxy_types.py | Adds five focused regression tests covering str(exc), the full StandardLoggingPayloadSetup.get_error_information chain, to_dict() shape stability, the 429 routing-code remap, and non-string message coercion. All tests are pure unit tests with no real network calls. |
Reviews (1): Last reviewed commit: "fix(proxy): clean up unintended drift; k..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
1fe911d
into
BerriAI:litellm_oss_agent_shin_daily_branch
Summary
ProxyException.__init__stores the human-readable message onself.messagebut never callssuper().__init__(self.message), soException.argsstays empty andstr(exc)returns"".Logging integrations such as
StandardLoggingPayloadSetup.get_error_information(consumed byproxy_track_cost_callback, Datadog, OpenTelemetry, S3, etc.) callstr(original_exception)to populateStandardLoggingPayloadErrorInformation.error_message. The empty string then ends up in logs/telemetry for everyProxyException-based failure — most visibly for 401 auth errors raised before a provider is selected (llm_providerblank is expected in that case).Fix
In
ProxyException.__init__, immediately afterself.message = str(message), callsuper().__init__(self.message). Five extra lines (one functional + four comment lines). The existingcoderemap logic ("No healthy deployment available"→ 429, tag-routing → 401) is preserved because it runs later onself.code, not onargs.Evidence
Reproduced on clean
main(commit06f6cfc) and re-run on this branch.Before — clean main, real
ProxyExceptionflowed through the real logging chain:After — patched branch, same call:
After — four real ProxyException shapes through the full proxy logging chain, all now propagate to
payload.error_message:Regression tests added in
tests/test_litellm/proxy/test_proxy_types.py(all pass on the patched branch):Five new regression tests cover:
str(ProxyException) == message(the immediate bug)StandardLoggingPayloadSetup.get_error_information(...)chain returns the populated messageto_dict()shape unchanged"No healthy deployment available"→ 429 code remap still worksmessageis still coercedNotes for reviewers
# NOTE: DO NOT MODIFY THIScomment inProxyExceptionis about the OpenAI-shape mapping (code,type,param,openai_code,to_dict()keys). This change does not touch any of that — it only populatesException.argssostr(self)works.repo/workflowscopes forgit push), one commit per file plus one cleanup commit. Net diff is the two-file change above; intermediate commit messages are noisier than the final state.959288c) necessary; the cumulative effect against the base branch is+5 / 0in_types.pyand+74 / 0in the test file.Fixes LIT-3094.
Verification (ship-pr)
litellm/proxy/_types.py(exception class, backend logging surface) +tests/test_litellm/proxy/test_proxy_types.py(tests). Required evidence: chained call output through the actual logging code path. PASS — see Evidence section.ProxyExceptionshapes throughStandardLoggingPayloadSetup.get_error_informationchain).StandardLoggingPayloadSetup.get_error_informationthatproxy_track_cost_callback, Datadog, OpenTelemetry, and S3 callbacks call inside the running proxy.