Skip to content

Conversation

@Mr-Neutr0n
Copy link

Summary

  • Replace all bare except: clauses with except Exception: across the codebase

Problem

Bare except: catches BaseException, which includes SystemExit, KeyboardInterrupt, and GeneratorExit. This can:

  • Prevent clean process shutdowns (e.g., Ctrl+C / SIGTERM gets swallowed)
  • Mask critical system-level exceptions that should propagate
  • Make debugging significantly harder by silently catching unexpected errors

Changes

Replaced except: with except Exception: in four files:

File Context
fastchat/serve/api_provider.py Streaming response chunk parsing in reka_api_stream_iter
fastchat/serve/monitor/monitor.py Model name lookup in get_combined_table
fastchat/utils.py Retry loop in image_moderation_request
playground/test_embedding/test_semantic_search.py cosine_similarity error handling

Why except Exception instead of more specific types

except Exception is the standard Python best practice for broad error handling (PEP 8). It catches all "regular" exceptions while correctly allowing SystemExit, KeyboardInterrupt, and GeneratorExit to propagate. This is the minimal safe fix with no behavioral change for normal error paths.

Test plan

  • No behavioral change for normal exception handling — Exception is the base class for all non-system exceptions
  • Verified no remaining bare except: clauses in the codebase

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant