Skip to content

Commit d980c3c

Browse files
EstrellaXDclaude
andcommitted
fix(parser): handle None return from raw_parser to avoid AttributeError (#992)
When raw_parser fails to parse non-episodic resources (movies, collections), it returns None. Add guard clause in title_parser to skip these gracefully instead of crashing on attribute access. Downgrade log level from error to info since this is expected behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 66a2b45 commit d980c3c

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

backend/src/module/parser/analyser/raw_parser.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
SUB_RE = re.compile(r"[简繁日字幕]|CH|BIG5|GB")
1515

1616
FALLBACK_EP_PATTERNS = [
17-
re.compile(r" (\d+) ?(?=\[)"), # #876/#910: digits before [
18-
re.compile(r"\[(\d+)\(\d+\)\]"), # #773: [02(57)]
17+
re.compile(r" (\d+) ?(?=\[)"), # #876/#910: digits before [
18+
re.compile(r"\[(\d+)\(\d+\)\]"), # #773: [02(57)]
1919
]
2020

2121
PREFIX_RE = re.compile(r"[^\w\s\u4e00-\u9fff\u3040-\u309f\u30a0-\u30ff-]")
@@ -32,6 +32,7 @@ def _fallback_parse(content_title: str) -> tuple | None:
3232
return season_info, episode_info, other
3333
return None
3434

35+
3536
CHINESE_NUMBER_MAP = {
3637
"一": 1,
3738
"二": 2,
@@ -201,7 +202,7 @@ def process(raw_title: str):
201202
def raw_parser(raw: str) -> Episode | None:
202203
ret = process(raw)
203204
if ret is None:
204-
logger.error(f"Parser cannot analyse {raw}")
205+
logger.info(f"Detected non-episodic resource: {raw}, skipping.")
205206
return None
206207
name_en, name_zh, name_jp, season, sr, episode, sub, dpi, source, group = ret
207208
return Episode(

backend/src/module/parser/title_parser.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def raw_parser(raw: str) -> Bangumi | None:
6868
episode = Episode(**episode_dict)
6969
else:
7070
episode = raw_parser(raw)
71+
if episode is None:
72+
return None
7173

7274
titles = {
7375
"zh": episode.title_zh,

0 commit comments

Comments
 (0)