Skip to content

Fix: add null checks for DOM elements in GetHoldingInformation#29

Open
HashidaTKS wants to merge 1 commit into
masterfrom
fix/scraper-get-holding-info-null-check
Open

Fix: add null checks for DOM elements in GetHoldingInformation#29
HashidaTKS wants to merge 1 commit into
masterfrom
fix/scraper-get-holding-info-null-check

Conversation

@HashidaTKS
Copy link
Copy Markdown
Owner

問題点

Scraper.GetHoldingInformation() で以下の3箇所において FirstOrDefault() の結果を null チェックせずに使用していた。

  • GetElementsByClassName("RaceList_Box").FirstOrDefault() (line 346)
  • GetElementsByClassName("RaceList_DataTitle").FirstOrDefault() (line 354)
  • GetElementsByClassName("RaceData").FirstOrDefault() (line 374)

開催情報がない日付や、ページ構造の変化により各要素が取得できなかった場合に NullReferenceException が発生する。

改善内容

  • RaceList_Box が見つからない場合は警告ログを出力して空の HoldingInformation を返す
  • RaceList_DataTitle / RaceData が null の場合はその行をスキップ(continue

Test plan

  • 通常の開催日で正常に情報が取得されることを確認
  • 開催がない日付や接続エラー時に例外が発生しないことを確認

🤖 Generated with Claude Code

Three FirstOrDefault() calls were not null-checked before being dereferenced:
- GetElementsByClassName("RaceList_Box").FirstOrDefault() — the top-level container
- GetElementsByClassName("RaceList_DataTitle").FirstOrDefault() — the title element per item
- GetElementsByClassName("RaceData").FirstOrDefault() — the data element per race item

If the page is empty or the structure changes, these return null and cause
NullReferenceException. Add explicit null guards and skip or return early
with an empty HoldingInformation when the container is absent.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant