Skip to content

fix: suppress noisy fake-useragent warning logs - #191

Open
boluwatifeajayi wants to merge 1 commit into
bisohns:masterfrom
boluwatifeajayi:fix/fake-useragent-index-error
Open

fix: suppress noisy fake-useragent warning logs#191
boluwatifeajayi wants to merge 1 commit into
bisohns:masterfrom
boluwatifeajayi:fix/fake-useragent-index-error

Conversation

@boluwatifeajayi

Copy link
Copy Markdown

Closes #159

What's actually happening

This was never an unhandled crash. fake-useragent already recovers internally when its cache server is unreachable or returns unexpected data — it falls back to querying the server directly for JSON. But it logs that recovery as a WARNING with a full traceback attached (exc_info=exc), which looks alarming even though nothing failed.

On top of that, get_rand_user_agent() in this repo already wraps the whole thing in a try/except with its own static fallback list — a second layer of defense that was already working. The traceback users saw in #159 was pure log noise, not an actual bug (see the issue itself: the very next line shown is a successful SearchResult).

Fix

Suppressed fake_useragent's own logger to ERROR level, scoped strictly to that logger — nothing else in the dependency tree is touched.

Testing

Added tests/test_utils.py covering get_rand_user_agent():

  • Mocks fake_useragent.UserAgent to force the internal failure path
  • Asserts no WARNING-or-above log record reaches the fake_useragent logger
  • Asserts the static fallback list still returns a valid user agent string

Verified the test actually catches a regression (not just passing vacuously) by temporarily reverting the suppression line and confirming the test fails, then restoring it.

Full suite: 43 passed (up from 42 baseline), pre-existing 4 failed/21 errors unchanged and unrelated (stale VCR cassettes, hostname-matcher mismatches — confirmed identical on baseline via git stash).

Scope note

Left requirements/main.txt's fake-useragent<0.2 pin untouched. That ceiling excludes the entire 1.x/2.x rewrite (which removed the remote-server dependency causing this entirely) — a bigger, separate decision since fake-useragent is now archived upstream.

fake-useragent already recovers internally from cache-server failures,
but logs the recovery as a warning with a full traceback attached. This
repo's own get_rand_user_agent() is a second layer of defense on top of
that, so the traceback was pure noise that led users to file bug reports
for something that was never actually failing.

Scoped the suppression to the fake_useragent logger only.

Closes bisohns#159
Copilot AI review requested due to automatic review settings July 25, 2026 02:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

list index out of range

2 participants