refactor: extract module-local _emit_http_error helper in models/search.py (BE-2143)#484
refactor: extract module-local _emit_http_error helper in models/search.py (BE-2143)#484mattmillerai wants to merge 1 commit into
Conversation
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 20 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
ELI-5
Two spots in
comfy models(thelist-foldersandsearchcommands) had theexact same copy-pasted block for turning an HTTP failure into a nice error:
pick a cloud-vs-local error code, and stuff a truncated, decoded copy of the
server's response body into the error details. This PR lifts that duplicated
block into one small helper next to them, so the idiom lives in one place.
What changed
_emit_http_error(e, *, renderer, target, message, hint)in
comfy_cli/command/models/search.py. It reproduces the shared idiomverbatim:
code = cloud_http_error if target.is_cloud else server_not_running,and
details={"status": e.code, "body": (e.read() or b"")[:1000].decode("utf-8","replace")}.It's annotated
-> NoReturn(it always ends inraise typer.Exit(code=1) from e).list_folders_cmdandsearch_cmdHTTPError handlers now call the helper.message/hintare the only per-caller differences, so they stay at the callsites.
branches for
list-folders, plus thesearchcloud path — asserting theerror code and the truncated/decoded
details.body. No such tests existedbefore.
Scope (deliberately narrow)
Per the ticket's corrected recommendation (downgraded from the original,
overstated finding), this is a module-local extraction shared by the two
sites that actually share the body-decode idiom. The other HTTPError handlers do
NOT share it and are intentionally left untouched:
list-folder(404-special-cased,details={status, folder}, no body decode)show(fixedcloud_http_error,details={status}, no body decode)URLError/OSError/JSONDecodeErrorhandlers (no body decode)No cross-module
emit_http_errorwas built — thetransfer.py/project.py/run/execution.pysites cited in the original finding don't share the idiom andwould be forced through parameters they don't want.
Verification
pytest tests/comfy_cli— 2218 passed, 12 skipped.ruff check+ruff format --checkclean on both changed files.Judgment call
(BE-####)suffix(matches recent history, e.g.
(BE-2142),(BE-992)).