Skip to content

Handle GitHub API exceptions in feature-links task - #6673

Open
love12yadav wants to merge 1 commit into
GoogleChrome:mainfrom
love12yadav:fix-feature-links-exception-handling
Open

Handle GitHub API exceptions in feature-links task#6673
love12yadav wants to merge 1 commit into
GoogleChrome:mainfrom
love12yadav:fix-feature-links-exception-handling

Conversation

@love12yadav

Copy link
Copy Markdown
Contributor

Summary

Fixes the feature-links cron/task pipeline so that a single failed GitHub API call (most commonly caused by rate limiting) no longer interrupts an entire batch of link updates.

Addresses #6632

Problem

internals/link_helpers.py's Link.parse() only handles a fixed set of exception types (requests.RequestException, HTTPError, ValueError, APIError).

When GitHub rate-limits requests (403/429), the underlying client may raise an exception outside this handled set. The exception then propagates through _index_feature_links_by_ids() in internals/feature_links.py, which previously had no exception handling.

This caused the /tasks/update-feature-links handler to return a 500 response, triggering Cloud Tasks retries on the same batch of links. The task would repeatedly fail instead of degrading gracefully.

Changes
internals/feature_links.py
Wrapped the per-link Link(...).parse() call inside _index_feature_links_by_ids() with try/except Exception so unexpected failures no longer terminate the entire batch.
Added _http_status_code_from_exception() and _normalise_http_status_code() helpers to extract HTTP status codes from common exception formats (.status_code, .status, .code, and nested .response objects).
Detect 403/429 rate-limit responses from:
raised exceptions, and
Link.parse() results (is_error / http_error_code).
Stop processing gracefully when rate limiting is detected, logging a warning with the number of remaining unprocessed links. Remaining links will be retried during the next scheduled run.
Handle non-rate-limit failures on individual links by recording the error on the corresponding FeatureLinks entity (is_error / http_error_code) and continuing processing of remaining links.

Fixes #6632

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.

feature-links task has exceptions

1 participant