Skip to content

[Code Quality] Add debug log to silent httpx.HTTPError in _fetch_folder_rules nested helper #595

@github-actions

Description

@github-actions

Description

The nested _fetch_folder_rules() helper inside get_all_existing_rules() silently swallows httpx.HTTPError without any log output:

# main.py ~line 1588
def _fetch_folder_rules(folder_id: str) -> list[str]:
    try:
        data = _api_get(client, f"{API_BASE}/{profile_id}/rules/{folder_id}").json()
        folder_rules = data.get("body", {}).get("rules", [])
        return [rule["PK"] for rule in folder_rules if rule.get("PK")]
    except httpx.HTTPError:
        return []          # ← HTTP errors are silently dropped
    except Exception as e:
        log.warning(...)   # generic errors DO log
        return []

This means that if the API returns a 4xx/5xx for a specific folder's rules endpoint, the function returns an empty list with no indication to the operator. The outer function only logs for generic Exception, not for httpx.HTTPError.

This is distinct from issue #589, which targets the root-level except httpx.HTTPError: pass in the same function. This issue targets the per-folder inner helper.

Suggested Changes

  1. Add a log.debug() call before return [] in the except httpx.HTTPError branch of _fetch_folder_rules:
    except httpx.HTTPError as e:
        log.debug("HTTP error fetching rules for folder %s: %s", folder_id, sanitize_for_log(e))
        return []
  2. Use log.debug (not log.warning) since transient folder errors are expected and shouldn't spam operators; debug level is sufficient for diagnostic purposes
  3. Add a unit test that verifies the debug log message is emitted when _api_get raises httpx.HTTPError for a folder

Files Affected

  • main.py (~lines 1588-1601, _fetch_folder_rules nested function)
  • tests/ — add test for debug log on folder HTTP error

Success Criteria

  • _fetch_folder_rules emits a log.debug() message (including sanitized error and folder ID) when an httpx.HTTPError occurs
  • log.warning() is NOT used (avoid alarming operators for expected transient errors)
  • sanitize_for_log() wraps the exception in the log call
  • Existing tests pass; new test verifies the debug log path

Source

Identified from discussion #586 QA analysis and code inspection. Related to open issue #589 (root-level silent HTTP error in the same function).

Priority

Low — improves debug-level observability for folder rule fetching; consistent with the logging improvements in issue #589.

🔍 Task mining by Discussion Task Miner - Code Quality Improvement Agent

To install this agentic workflow, run

gh aw add github/gh-aw/.github/workflows/discussion-task-miner.md@94662b1dee8ce96c876ba9f33b3ab8be32de82a4
  • expires on Mar 7, 2026, 5:16 PM UTC

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions