1
0
Fork 0
mirror of https://codeberg.org/Reuh/feather.git synced 2025-12-14 07:19:08 +00:00

fix: skip corrupted articles instead of aborting the whole program

This commit is contained in:
Étienne Fildadut 2025-12-06 15:51:16 +01:00
parent 13d82f9913
commit 0aa10d4b02
2 changed files with 24 additions and 8 deletions

View file

@ -10,7 +10,7 @@ from datetime import datetime
from feather.config import Config
from feather.client import GReaderSession, TTRSession, ClientSession, Article, ArticleId
from feather.data import FileArticle
from feather.data import FileArticle, InvalidArticleFileError
async def sleep_min_max(min_sleep: float, max_sleep: float, stop_sleep_event: Event):
@ -53,7 +53,12 @@ class FeatherApp:
"""Iterate over all the articles in local storage"""
config = self.config
for json_path in config.json_root.glob("*.json"):
try:
yield FileArticle(config, json_path)
except InvalidArticleFileError:
print(
f"WARNING: Skipping corrupted article file {json_path}. Delete this file and its associated HTML file (if it exists) to resolve this warning."
)
def remove_empty_categories(self):
"""Remove empty directories in the HTML directory"""
@ -154,11 +159,16 @@ class FeatherApp:
article.write()
new_articles += 1
else:
try:
old_article = FileArticle(config, json_path)
if article.was_updated(old_article):
old_article.delete()
article.write()
updated_articles += 1
except InvalidArticleFileError:
print(
f" WARNING: Skipping corrupted article file {json_path}. Delete this file and its associated HTML file (if it exists) to resolve this warning."
)
# Remove or mark-as-read articles that we didn't get from the server but are in the JSON directory
removed_articles = 0

View file

@ -283,13 +283,19 @@ class Article(ABC):
self.delete() # paths might change so we preemptively remove the old file
self.write(recompute_paths=True) # rewrite JSON & HTML
class InvalidArticleFileError(ValueError):
pass
class FileArticle(Article):
def __init__(self, config: Config, json_path: Path) -> Article:
self.config = config
self.json_path = json_path
try:
article_json = json.load(json_path.open("r"))
except ValueError as e:
raise InvalidArticleFileError(f"Can't load article file {json_path}") from e
for field in article_json:
setattr(self, field, article_json[field])
self.category = Category.fromdict(article_json["category"])