Handle NewsScraper transport errors - #98
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates NewsScraper to align with the library’s other scrapers by converting HTTP/transport failures into a structured ScrapeResult containing a single ScrapeError, instead of allowing exceptions to propagate and crash callers.
Changes:
- Wrapped feed, site, and article fetch operations (sync + async) in transport guards that return a structured error
ScrapeResulton failure. - Refactored article scraping to separate fetching (
fetch_html*) from parsing (parse_html) so parser defects still raise. - Added regression tests covering transport failures across feed/site/article for both sync and async APIs, plus tests ensuring parse errors still propagate.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/pyscrappy/scrapers/news.py |
Adds transport error handling for feed/site/article paths and introduces a helper to build consistent error results without swallowing parser errors. |
tests/test_scrapers/test_news.py |
Adds sync/async tests asserting transport failures return structured ScrapeResult errors and that article parse failures still raise. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
vedaant00
marked this pull request as ready for review
August 5, 2026 08:35
Collaborator
|
Really clean fix. I especially like that you kept parse_html outside the transport guard (and split fetch_and_parse in the article path to do it) so parser bugs still surface, plus the test asserting that. Verified the suite passes. Merging, thanks @shard872! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ScrapeResulterrorsWhy
NewsScraper was the outlier among the API scrapers: failed HTTP requests escaped as exceptions and could crash callers instead of returning the library's normal
ScrapeErrorrepresentation. The article path also required separating fetch from parse so the fix would not hide parser failures.Impact
Callers now receive empty data plus one
ScrapeErrorcontaining the failed URL and transport message. Successful scraping, route priority, invalid XML behavior, and public method signatures are unchanged.Closes #87.
Verification
PYTHONPATH=src python3 -m pytest tests/test_scrapers/test_news.py -q— 21 passedPYTHONPATH=src python3 -m pytest tests/ -q— 384 passed, 5 skipped, 19 deselectedruff check src/— all checks passedgit diff --check— clean