From 892b9ee424f9fe79dad825f0d8a37e7a94dc3405 Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:00:01 +0530 Subject: [PATCH] Replace bare except clauses with except Exception Bare `except:` catches BaseException, which includes SystemExit, KeyboardInterrupt, and GeneratorExit. This can mask critical errors, prevent clean shutdowns (e.g., Ctrl+C ignored), and make debugging significantly harder. Using `except Exception:` instead preserves the intended error handling while allowing system-level exceptions to propagate correctly. Fixed in: - fastchat/serve/api_provider.py (streaming response handling) - fastchat/serve/monitor/monitor.py (model name lookup) - fastchat/utils.py (image moderation retry loop) - playground/test_embedding/test_semantic_search.py (cosine similarity) --- fastchat/serve/api_provider.py | 2 +- fastchat/serve/monitor/monitor.py | 2 +- fastchat/utils.py | 2 +- playground/test_embedding/test_semantic_search.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fastchat/serve/api_provider.py b/fastchat/serve/api_provider.py index 2e967e3ef..3c168d1a6 100644 --- a/fastchat/serve/api_provider.py +++ b/fastchat/serve/api_provider.py @@ -1262,7 +1262,7 @@ def reka_api_stream_iter( for chunk in response: try: yield {"text": chunk.responses[0].chunk.content, "error_code": 0} - except: + except Exception: yield { "text": f"**API REQUEST ERROR** ", "error_code": 1, diff --git a/fastchat/serve/monitor/monitor.py b/fastchat/serve/monitor/monitor.py index 462e38187..0509cf522 100644 --- a/fastchat/serve/monitor/monitor.py +++ b/fastchat/serve/monitor/monitor.py @@ -886,7 +886,7 @@ def get_model_name(model_key): "Model" ].values[0] return model_name - except: + except Exception: return None combined_table = [] diff --git a/fastchat/utils.py b/fastchat/utils.py index d3531928f..9d08c83af 100644 --- a/fastchat/utils.py +++ b/fastchat/utils.py @@ -450,7 +450,7 @@ def image_moderation_request(image_bytes, endpoint, api_key): try: if response["Status"]["Code"] == 3000: break - except: + except Exception: time.sleep(0.5) return response diff --git a/playground/test_embedding/test_semantic_search.py b/playground/test_embedding/test_semantic_search.py index 879b240b6..2db8c4333 100644 --- a/playground/test_embedding/test_semantic_search.py +++ b/playground/test_embedding/test_semantic_search.py @@ -11,7 +11,7 @@ def cosine_similarity(vec1, vec2): try: return 1 - cosine(vec1, vec2) - except: + except Exception: print(vec1.shape, vec2.shape)