Optimize code and enhance exception safety in repository and UI layers#476
Merged
ProdigyV21 merged 15 commits intoJul 23, 2026
Merged
Conversation
…ory and UI layers
### Summary of Changes - Extracted dynamic regex initializations from inline instantiations to statically cached top-level objects in HomeServerRepository.kt, StreamRepository.kt, PlayerViewModel.kt, and TelegramSearchMatcher.kt to improve performance and avoid GC churn. - Hardened error handling in TraktRepository.kt by replacing generic runCatching blocks with explicit try-catch blocks that properly handle coroutine cancellations. - Hardened error handling in HomeServerRepository.kt using proper try-catch. ### Why this improves the codebase - The performance is improved by eliminating unnecessary regex compilations inside loops. - Error handling is more robust and prevents coroutine cancellation exceptions from being silently swallowed, avoiding broken structured concurrency state. ### Verification - [x] Code compiles successfully inside the sandbox environment. - [x] No new features were added; existing features were fortified and optimized across the modified files. - [x] Automated tests pass (except for pre-existing unrelated test failures).
…repository layers
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors error handling across several repositories to use explicit
try/catchblocks instead ofrunCatching, improves logging for network and HTTP errors, and consolidates regex usage for home server matching. The changes aim to make error handling more robust, ensure proper cancellation propagation, and provide clearer diagnostics.Error handling improvements:
Replaced
runCatchingwith explicittry/catchblocks throughout the codebase for better control over exception handling, ensuringCancellationExceptionis always rethrown and other exceptions are logged appropriately. This affects repositories such asAppUsageAnalyticsRepository,CatalogDiscoveryRepository,CatalogRepository, andHomeServerRepository. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Improved network and HTTP error logging by adding more descriptive log messages, especially in cloud sync and analytics flows, to aid in debugging and monitoring. [1] [2] [3]
Code consistency and maintainability:
HomeServerRepositoryto theHomeServerRegexesandHomeServerXmlRegexCacheutility objects, improving maintainability and consistency. [1] [2] [3] [4] [5] [6]Minor improvements:
isNullOrBlankfor access tokens, preventing accidental header inclusion of blank tokens.import android.util.Logwhere needed. [1] [2]These changes collectively improve reliability, error visibility, and code clarity.