Replace bare except clauses with except Exception#3773
Open
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Open
Replace bare except clauses with except Exception#3773Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Mr-Neutr0n wants to merge 1 commit intolm-sys:mainfrom
Conversation
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
except:clauses withexcept Exception:across the codebaseProblem
Bare
except:catchesBaseException, which includesSystemExit,KeyboardInterrupt, andGeneratorExit. This can:Ctrl+C/SIGTERMgets swallowed)Changes
Replaced
except:withexcept Exception:in four files:fastchat/serve/api_provider.pyreka_api_stream_iterfastchat/serve/monitor/monitor.pyget_combined_tablefastchat/utils.pyimage_moderation_requestplayground/test_embedding/test_semantic_search.pycosine_similarityerror handlingWhy
except Exceptioninstead of more specific typesexcept Exceptionis the standard Python best practice for broad error handling (PEP 8). It catches all "regular" exceptions while correctly allowingSystemExit,KeyboardInterrupt, andGeneratorExitto propagate. This is the minimal safe fix with no behavioral change for normal error paths.Test plan
Exceptionis the base class for all non-system exceptionsexcept:clauses in the codebase