Skip to content

fix: render error UI for TopicUiState.Error instead of crashing#2109

Open
Noahs212 wants to merge 1 commit into
android:mainfrom
Noahs212:fix/topic-screen-error-state
Open

fix: render error UI for TopicUiState.Error instead of crashing#2109
Noahs212 wants to merge 1 commit into
android:mainfrom
Noahs212:fix/topic-screen-error-state

Conversation

@Noahs212
Copy link
Copy Markdown

@Noahs212 Noahs212 commented May 15, 2026

Summary

  • Replace TopicUiState.Error -> TODO() (TopicScreen.kt:132) with a localized error message. TODO() throws NotImplementedError at runtime, so the topic detail screen currently crashes whenever the upstream topic flow emits an error (Result.Error from asResult).
  • Add feature_topic_api_error_header string and a private TopicErrorBody composable modeled on SearchNotReadyBody.
  • Update topicItemsSize so the scrollbar item count matches the rendered error item (0 -> 1).
  • Add errorMessage_whenTopicIsError_isShown to TopicScreenTest. This test fails on main with NotImplementedError and passes after the fix.

The other two TODOs in the same file (hardcoded "Loading news" at L249 and Text("Error") at L253) are in the NewsUiState branch and intentionally out of scope to keep this diff small.

Fixes #2108

Test plan

  • ./gradlew :feature:topic:impl:connectedDemoDebugAndroidTest --tests "*TopicScreenTest*"
  • ./gradlew :feature:topic:impl:testDemoDebugUnitTest
  • ./gradlew spotlessApply
  • ./gradlew :feature:topic:impl:lintDemoDebug :feature:topic:api:lintDemoDebug
  • Manually verify on a device: force a topic-flow error and confirm the error text appears instead of a crash.

@Noahs212 Noahs212 requested a review from dturner as a code owner May 15, 2026 18:56
@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 15, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements the error state for the Topic screen by adding a new error message string, a TopicErrorBody composable, and updating the UI logic to handle TopicUiState.Error. It also includes a new UI test to verify the error message display. Feedback highlights that the topicItemsSize calculation for the success state may be incomplete, potentially affecting scrollbar accuracy, and suggests adding a modifier parameter to the TopicErrorBody composable to follow Compose best practices.

newsUiState: NewsUiState,
) = when (topicUiState) {
TopicUiState.Error -> 0 // Nothing
TopicUiState.Error -> 1 // Error message
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While updating this to 1 is correct for the new error state, the existing logic for TopicUiState.Success (lines 185-186) appears to be incorrect as it doesn't account for the Toolbar and Header items which are always rendered in that state. This discrepancy will cause the scrollbar to be incorrectly sized or hidden when news is loading or has an error. Consider updating the entire function to ensure the scrollbar accurately reflects the number of items in the LazyColumn.

Comment on lines +209 to +212
private fun TopicErrorBody() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is a best practice in Compose to have a modifier parameter for all composables to allow for layout adjustments from the caller. This also ensures that the internal Column uses the passed-in modifier as its base.

Suggested change
private fun TopicErrorBody() {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
private fun TopicErrorBody(modifier: Modifier = Modifier) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = modifier

@Noahs212 Noahs212 force-pushed the fix/topic-screen-error-state branch 3 times, most recently from 8d57c33 to 45cb357 Compare May 15, 2026 19:10
@Noahs212 Noahs212 force-pushed the fix/topic-screen-error-state branch from 45cb357 to c160d18 Compare May 15, 2026 19:12
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.

[Bug]: TopicScreen crashes when TopicUiState.Error is emitted (TODO() in production)

1 participant