android / android/nowinandroid

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

Open
#2,108 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is there a StackOverflow question about this issue?

- [X] I have searched StackOverflow

### What happened?

`TopicScreen` calls `kotlin.TODO()` for the `TopicUiState.Error` branch, which throws `NotImplementedError` at runtime and crashes the screen whenever the underlying topic flow surfaces an error.

Reachability:

- `TopicViewModel.topicUiState` runs `topicsRepository.getTopic(id).asResult()`.
- `core.common.result.Result.asResult` catches any `Throwable` from upstream and emits `Result.Error(it)` (see `core/common/.../result/Result.kt:32`).
- `TopicViewModel` maps `Result.Error -> TopicUiState.Error` (`TopicViewModel.kt:131`).
- `TopicScreen` then hits `TopicUiState.Error -> TODO()` (`TopicScreen.kt:132`) and crashes.

Any exception thrown by the Room flow (DB IO error, mapper failure, etc.) or any upstream operator therefore crashes the topic detail screen instead of showing an error UI.

The branch is also untested: `TopicScreenTest` only drives `TopicUiState.Loading` and `TopicUiState.Success`.

### Relevant logcat output

\`\`\`shell
FATAL EXCEPTION: main
kotlin.NotImplementedError: An operation is not implemented.
at com.google.samples.apps.nowinandroid.feature.topic.impl.TopicScreenKt.TopicScreen(TopicScreen.kt:132)
\`\`\`

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start with TopicScreen.kt:132, then read TopicViewModel.kt:131 and Result.kt:32 to trace the Error state. Run TopicScreenTest and extend it to cover TopicUiState.Error. Done means the error state no longer reaches TODO() or crashes the screen, with test coverage for that path.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, kotlin
Domain
mobile
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.