From d7450305391fd604609d0aaad1359f20d2450eec Mon Sep 17 00:00:00 2001 From: JingHao-Leon <102573344+JingHao-Leon@users.noreply.github.com> Date: Sun, 11 Oct 2026 12:30:23 +0800 Subject: [PATCH] fix(streaming): annotate the three intentional blind excepts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ruff_strict_gate.py` counts BLE001 against a ceiling taken at the merge-base, and the abandoned-stream cleanup path added three: - around `stream_chunk_builder` — a failure here means the partial call cannot be assembled, and it is already logged rather than raised; - around closing the provider stream — must not mask the caller's own error; - in `__del__` — a finalizer must never raise, and the logging is best-effort. Each is suppressed with that reason, matching the existing `# noqa: BLE001` usages elsewhere in litellm. The file's BLE001 count is back to the merge-base baseline (48 -> 48). --- litellm/litellm_core_utils/streaming_handler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index 3663634fcaf..20495359c31 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -332,7 +332,7 @@ class CustomStreamWrapper: logging_obj=self.logging_obj, count_prompt_tokens=self.count_prompt_tokens, ) - except Exception as e: + except Exception as e: # noqa: BLE001 # an abandoned stream must still emit whatever telemetry was built; the failure is logged, not raised verbose_logger.warning( "stream_chunk_builder raised for an abandoned stream (%s); the partial call is not logged.", str(e), @@ -378,7 +378,7 @@ class CustomStreamWrapper: if stream_to_close is not None and hasattr(stream_to_close, "close"): # pyright: ignore[reportUnknownArgumentType] # provider-specific stream object try: stream_to_close.close() # pyright: ignore[reportUnknownMemberType] # provider-specific stream object - except Exception as e: + except Exception as e: # noqa: BLE001 # closing a provider stream must not mask the caller's own error verbose_logger.debug("closing the underlying stream failed: %s", str(e)) self._restore_consumer_correlation_context() @@ -454,7 +454,7 @@ class CustomStreamWrapper: self._restore_consumer_correlation_context(guarded=True) try: self._flush_abandoned_stream_logging() - except Exception: + except Exception: # noqa: BLE001 # __del__ must never raise; logging here is best-effort verbose_logger.debug("abandoned-stream logging failed in __del__", exc_info=True) async def aclose(self):