Skip to content

refactor: extract module-local _emit_http_error helper in models/search.py (BE-2143)#484

Open
mattmillerai wants to merge 1 commit into
mainfrom
matt/be-2143-emit-http-error
Open

refactor: extract module-local _emit_http_error helper in models/search.py (BE-2143)#484
mattmillerai wants to merge 1 commit into
mainfrom
matt/be-2143-emit-http-error

Conversation

@mattmillerai

Copy link
Copy Markdown
Collaborator

ELI-5

Two spots in comfy models (the list-folders and search commands) had the
exact 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

  • New module-local helper _emit_http_error(e, *, renderer, target, message, hint)
    in comfy_cli/command/models/search.py. It reproduces the shared idiom
    verbatim: 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 in raise typer.Exit(code=1) from e).
  • list_folders_cmd and search_cmd HTTPError handlers now call the helper.
    message/hint are the only per-caller differences, so they stay at the call
    sites.
  • Added regression tests covering both extracted paths — cloud and local
    branches for list-folders, plus the search cloud path — asserting the
    error code and the truncated/decoded details.body. No such tests existed
    before.

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 (fixed cloud_http_error, details={status}, no body decode)
  • the sibling URLError/OSError/JSONDecodeError handlers (no body decode)

No cross-module emit_http_error was built — the transfer.py / project.py /
run/execution.py sites cited in the original finding don't share the idiom and
would be forced through parameters they don't want.

Verification

  • pytest tests/comfy_cli — 2218 passed, 12 skipped.
  • ruff check + ruff format --check clean on both changed files.

Judgment call

  • Pure refactor, behavior-preserving; no functional change to emitted errors.
  • Followed the repo's own PR/commit convention of the (BE-####) suffix
    (matches recent history, e.g. (BE-2142), (BE-992)).

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 20 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 27dbd6cc-cae4-46fc-9b19-8ed0a9f91310

📥 Commits

Reviewing files that changed from the base of the PR and between 7e87c77 and e932759.

📒 Files selected for processing (2)
  • comfy_cli/command/models/search.py
  • tests/comfy_cli/command/models/test_search.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matt/be-2143-emit-http-error
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch matt/be-2143-emit-http-error

Comment @coderabbitai help to get the list of available commands.

@mattmillerai mattmillerai added agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review labels Jul 2, 2026
@mattmillerai mattmillerai marked this pull request as ready for review July 2, 2026 02:12
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 2, 2026
@mattmillerai mattmillerai requested a review from skishore23 July 2, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants