fix: shift_usecase の Find→Scan 連鎖でのエラー握り潰しを解消#378
Conversation
|
Warning Review limit reached
More reviews will be available in 36 minutes and 53 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Changesshift_usecase.go Find→Scan エラーハンドリング強化
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
🧹 Nitpick comments (1)
api/lib/usecase/shift_usecase.go (1)
199-206: 🗄️ Data Integrity & Integration | 🔵 Trivial
CreateShiftAdminはFindLatestRecordではなくCreateAndReturnIDを使いたい。Create後に最新1件を再取得する方式だと、同時作成時に別リクエストの行を返す可能性があります。RETURNING idで対象レコードを直接取得する方が安全です。🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@api/lib/usecase/shift_usecase.go` around lines 199 - 206, CreateShiftAdmin currently calls u.rep.Create and then u.rep.FindLatestRecord, which can return the wrong row under concurrent inserts. Update the CreateShiftAdmin flow in shift_usecase.go to use u.rep.CreateAndReturnID instead of re-querying the latest record, and propagate the returned row/id directly from that call. Keep the existing error handling around the repository call, and remove the FindLatestRecord dependency from this path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@api/lib/usecase/shift_usecase.go`:
- Around line 199-206: CreateShiftAdmin currently calls u.rep.Create and then
u.rep.FindLatestRecord, which can return the wrong row under concurrent inserts.
Update the CreateShiftAdmin flow in shift_usecase.go to use
u.rep.CreateAndReturnID instead of re-querying the latest record, and propagate
the returned row/id directly from that call. Keep the existing error handling
around the repository call, and remove the FindLatestRecord dependency from this
path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 8982f65f-3413-44b6-8f80-5a53a7ddd0cf
📒 Files selected for processing (1)
api/lib/usecase/shift_usecase.go
概要
shift_usecase.go の4関数で、Find→Scan が連鎖する箇所のエラーが握り潰されていた(ineffassign 12件)。各 Find/Scan の直後に
if err != nil { return }を追加して解消した。変更した関数
CreateShiftAdmin の本物のバグ
修正前:
Create が失敗しても FindLatestRecord に進み、別ユーザーの最新シフト行を「自分の作成結果」として返していた。修正後は Create 失敗を呼び出し側に正しく伝播する。
安全性確認
if err != nil { return }が no-op なので挙動変化なし既存の lint 警告について
golangci-lint runに5件の既存警告が残るが、いずれも今回の変更とは無関係のファイル(rescue_unified_usecase.go / mail_auth_usecase.go / user_usecase.go)。CI はonly-new-issues: trueのため影響なし。Closes #369
Summary by CodeRabbit