fix: add nil checks in htmlURL to prevent panic#289
Conversation
Add nil pointer checks for Issue/PullRequest and HTMLURL fields in event payloads. Event payloads may contain nil values when resources are deleted or inaccessible, unlike fresh API responses. This fixes a panic that occurs when processing events with missing data: - Check Issue/PullRequest is not nil before accessing - Check HTMLURL is not nil before dereferencing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
WalkthroughNil-safety checks were added in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
lib/events.go (1)
123-154: Replace htmlURL-based deduplication with event.ID for uniqueness.The current
uniqfunction (lines 104-119) deduplicates events using their HTML URLs as keys. When nil checks inhtmlURL()fail, it returns an empty string, causing all events with missing URLs to be treated as the same event. This loses distinct valid events.Since github.Event has an ID field (*string) in go-github v69, using
event.IDas the deduplication key would be more robust and prevent data loss for events lacking HTML URLs.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
lib/events.go(1 hunks)
🔇 Additional comments (1)
lib/events.go (1)
132-150: Nil checks correctly prevent panic across all event types.The nil checks are properly implemented with consistent guarding of both parent objects (Issue/PullRequest) and their nested HTMLURL pointers before dereferencing. This solves the panic issue described in the PR objectives.
masutaka
left a comment
There was a problem hiding this comment.
ありがとうございます!ちょうど今週この問題に気づき、なぜ過去のリリースも panic になるんだろう?自分の環境問題?などと考えていたところでした。
|
確認ありがとうございます!ライブラリのアップデートによるものじゃないのか??と気になっていたところでした。 |
|
リリース前には毎回ローカルで動作確認しているので、ライブラリのアップデートによるものではないはず 🙃 |
問題
github-nippou listコマンド実行時に nil pointer dereference が発生し、panic でクラッシュする問題を修正しました。原因
lib/events.goのhtmlURL関数で、イベントペイロード内のIssue/PullRequestおよびHTMLURLフィールドが nil の場合のチェックが不足していました。go-github ライブラリでは、これらのフィールドは
omitemptyタグ付きのポインタ型として定義されており、GitHub API の仕様上 nil になる可能性があります:発生時期
私の環境では、この問題は2025年10月頃から発生し始めました。
調査の結果、最近の go-github のアップデート(v63 → v69、2025年2月10日)では、イベントタイプに関する破壊的変更は含まれていませんでした。これは潜在的にずっと存在していたバグであり、最近になって顕在化した理由として以下が考えられます:
pull_requestフィールドを省略するようになった可能性修正内容
全てのイベントタイプで nil チェックを追加しました:
テスト
修正後、問題なく動作することを確認:
Summary by CodeRabbit