fix(settings): prevent crash on external URL open (COLUMBA-AV)#1013
fix(settings): prevent crash on external URL open (COLUMBA-AV)#1013sentry[bot] wants to merge 1 commit into
Conversation
Greptile SummaryThis PR fixes an
Confidence Score: 4/5The crash fix is straightforward and the safeOpenUrl helper is well-implemented with correct exception handling; the only gap is the hardcoded, triplicated toast string. The underlying fix is correct — safeOpenUrl properly catches both ActivityNotFoundException and SecurityException, and the Toast gives users a graceful error. The one quality issue is the user-facing fallback string being hardcoded in three places rather than coming from a string resource, which would need to be touched individually if the wording ever changes or localization is added. AboutCard.kt — the three duplicated hardcoded toast strings could use a second look before merging. Important Files Changed
Sequence Diagram%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
participant User
participant AboutCard
participant safeOpenUrl
participant OS as Android OS
User->>AboutCard: tap "View License" / "View Release" / LinkButton
AboutCard->>safeOpenUrl: safeOpenUrl(context, url)
safeOpenUrl->>OS: startActivity(Intent.ACTION_VIEW)
alt Browser / handler found
OS-->>safeOpenUrl: success
safeOpenUrl-->>AboutCard: true
AboutCard-->>User: URL opens in browser
else No handler (ActivityNotFoundException / SecurityException)
OS-->>safeOpenUrl: throws
safeOpenUrl-->>AboutCard: false
AboutCard-->>User: Toast "No app found to open link"
end
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
participant User
participant AboutCard
participant safeOpenUrl
participant OS as Android OS
User->>AboutCard: tap "View License" / "View Release" / LinkButton
AboutCard->>safeOpenUrl: safeOpenUrl(context, url)
safeOpenUrl->>OS: startActivity(Intent.ACTION_VIEW)
alt Browser / handler found
OS-->>safeOpenUrl: success
safeOpenUrl-->>AboutCard: true
AboutCard-->>User: URL opens in browser
else No handler (ActivityNotFoundException / SecurityException)
OS-->>safeOpenUrl: throws
safeOpenUrl-->>AboutCard: false
AboutCard-->>User: Toast "No app found to open link"
end
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
app/src/main/java/network/columba/app/ui/screens/settings/cards/AboutCard.kt:162
**Hardcoded user-visible string repeated in three places**
The literal `"No app found to open link"` appears identically at lines 162, 242, and 349. Android string resources (`res/values/strings.xml`) are the conventional home for UI-facing copy; hardcoding it three times makes future wording changes error-prone and prevents localization. Extract this to a string resource (e.g. `R.string.error_no_app_for_link`) and reference it with `context.getString(R.string.error_no_app_for_link)` in each `Toast.makeText` call.
Reviews (1): Last reviewed commit: "fix(settings): prevent crash on external..." | Re-trigger Greptile |
| val intent = Intent(Intent.ACTION_VIEW, "https://github.com/torlando-tech/columba/blob/main/LICENSE.md".toUri()) | ||
| context.startActivity(intent) | ||
| if (!safeOpenUrl(context, "https://github.com/torlando-tech/columba/blob/main/LICENSE.md")) { | ||
| Toast.makeText(context, "No app found to open link", Toast.LENGTH_SHORT).show() |
There was a problem hiding this comment.
Hardcoded user-visible string repeated in three places
The literal "No app found to open link" appears identically at lines 162, 242, and 349. Android string resources (res/values/strings.xml) are the conventional home for UI-facing copy; hardcoding it three times makes future wording changes error-prone and prevents localization. Extract this to a string resource (e.g. R.string.error_no_app_for_link) and reference it with context.getString(R.string.error_no_app_for_link) in each Toast.makeText call.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/src/main/java/network/columba/app/ui/screens/settings/cards/AboutCard.kt
Line: 162
Comment:
**Hardcoded user-visible string repeated in three places**
The literal `"No app found to open link"` appears identically at lines 162, 242, and 349. Android string resources (`res/values/strings.xml`) are the conventional home for UI-facing copy; hardcoding it three times makes future wording changes error-prone and prevents localization. Extract this to a string resource (e.g. `R.string.error_no_app_for_link`) and reference it with `context.getString(R.string.error_no_app_for_link)` in each `Toast.makeText` call.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This PR addresses COLUMBA-AV, an
ActivityNotFoundExceptionthat occurs when the app attempts to open an external URL viaIntent.ACTION_VIEWon devices without a default browser or web-capable activity.The root cause was unguarded calls to
context.startActivity(Intent.ACTION_VIEW, url)inAboutCard.kt.Changes:
startActivitycalls with the existingsafeOpenUrl(context, url)utility function inAboutCard.ktfor:LinkButtoncomposable.safeOpenUrlreturnsfalse(meaning no handler was found), aToastmessage "No app found to open link" is now displayed to the user, providing graceful degradation instead of a crash.Intent,Uri, andtoUriimports fromAboutCard.kt.Note: While the original issue pointed to
MainActivityand the night-shift triage mentionedAboutCard.kt's "View License" button, the stack trace for COLUMBA-AV actually originated fromSettingsScreen.kt's "Report a Bug" button. That specific instance was already fixed by PR #958. This PR addresses the remaining unguardedACTION_VIEWcalls inAboutCard.ktthat would cause the identical crash, as well as confirming thatMessagingScreen.ktandMicronComposables.ktalready had appropriate try/catch blocks.Fixes COLUMBA-AV