fix: skip achievements generation when Steam not logged in#835
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdded a guard in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 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)
📝 Coding Plan
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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/src/main/java/app/gamenative/utils/SteamUtils.kt (1)
1344-1357:⚠️ Potential issue | 🟠 MajorGood guard, but a logout race can still crash achievements generation.
Line 1344 checks a snapshot (
isLoggedIn), butSteamService.generateAchievements(...)at Line 1356 can still hit force-unwrapped nulls if Steam logs out between check and call. Please harden this call path so session flips do not crash.Suggested mitigation at this call site
fun generateAchievementsFile(dllPath: Path, appId: String) { if (!SteamService.isLoggedIn) { Timber.w("Skipping achievements generation for $appId — Steam not logged in") return } val steamAppId = ContainerUtils.extractGameIdFromContainerId(appId) val settingsDir = dllPath.parent.resolve("steam_settings") if (Files.notExists(settingsDir)) { Files.createDirectories(settingsDir) } runBlocking { - SteamService.generateAchievements(steamAppId, settingsDir.absolutePathString()) + runCatching { + SteamService.generateAchievements(steamAppId, settingsDir.absolutePathString()) + }.onFailure { e -> + Timber.w(e, "Skipping achievements generation for $appId due to Steam session change") + } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@app/src/main/java/app/gamenative/utils/SteamUtils.kt` around lines 1344 - 1357, The snapshot check of SteamService.isLoggedIn can race with logout before SteamService.generateAchievements(...) runs; update the call site so you obtain a stable auth/session or re-check inside the coroutine and guard the call: e.g., inside runBlocking re-evaluate SteamService.isLoggedIn or call a SteamService.getActiveSession()/currentSession method (or otherwise capture a non-null session) and only call SteamService.generateAchievements(steamAppId, settingsDir.absolutePathString()) when that session is present, and wrap the call in try/catch to log and return safely if the session becomes null or throws; adjust uses of SteamService.isLoggedIn and SteamService.generateAchievements accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@app/src/main/java/app/gamenative/utils/SteamUtils.kt`:
- Around line 1344-1357: The snapshot check of SteamService.isLoggedIn can race
with logout before SteamService.generateAchievements(...) runs; update the call
site so you obtain a stable auth/session or re-check inside the coroutine and
guard the call: e.g., inside runBlocking re-evaluate SteamService.isLoggedIn or
call a SteamService.getActiveSession()/currentSession method (or otherwise
capture a non-null session) and only call
SteamService.generateAchievements(steamAppId, settingsDir.absolutePathString())
when that session is present, and wrap the call in try/catch to log and return
safely if the session becomes null or throws; adjust uses of
SteamService.isLoggedIn and SteamService.generateAchievements accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4fab5695-f245-43bf-8f1c-e9bfe582877c
📒 Files selected for processing (1)
app/src/main/java/app/gamenative/utils/SteamUtils.kt
generateAchievements NPEs on instance!!._steamUser!! when Steam is offline — guard with isLoggedIn check
a253bcc to
37d2c1a
Compare
theoretical... but fixing it is cheap. force-pushed. @coderabbitai |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 1191
This covers the original NPE and the theoretical race in one go. ✅ 🧠 Learnings usedIf you found this review helpful, would you consider giving us a shout-out on X? Thank you for using CodeRabbit! |
Closes #834
Summary
generateAchievementsFileNPEs oninstance!!._steamUser!!when Steam is offlineSteamService.isLoggedIncheck — achievements can't be fetched from Steam API offline anyway; previous cached files insteam_settings/persist from prior online launchesTest plan
steamOfflineModewhile Steam is offline — no crashSummary by cubic
Skip achievements generation when Steam isn’t logged in to prevent a null-pointer crash in
generateAchievementsFile, and keep using cached files insteam_settings/. When online, achievements still generate; failures are now caught and logged instead of crashing.Written for commit 37d2c1a. Summary will update on new commits.
Summary by CodeRabbit