Problem
Currently, GhCliApiClient.executeCommand() throws a generic RuntimeException for all errors:
if (exitCode != 0) {
throw RuntimeException("gh command failed with exit code $exitCode: $output")
}
This doesn't distinguish between:
- GitHub CLI not installed
- Not authenticated (
gh auth login needed)
- GitHub API errors (rate limit, not found, etc.)
- Network connectivity issues
Proposed Solution
- Parse GH CLI error output to identify specific error types
- Create custom exceptions for different error scenarios:
GhCliNotAuthenticatedException
GhCliRateLimitException
GhCliNetworkException
- Map to existing error handling via
ErrorProcessor
- Provide actionable error messages to users
Example:
private fun executeCommand(command: List<String>): String {
val process = ProcessBuilder(command).redirectErrorStream(true).start()
val output = BufferedReader(InputStreamReader(process.inputStream)).use { it.readText() }
val exitCode = process.waitFor()
if (exitCode != 0) {
when {
output.contains("authentication") || output.contains("not logged in") ->
throw IllegalStateException("GitHub CLI not authenticated. Run: gh auth login")
output.contains("rate limit") ->
throw RuntimeException("GitHub API rate limit exceeded: $output")
output.contains("not found") ->
throw RuntimeException("Resource not found: $output")
else ->
throw RuntimeException("gh command failed with exit code $exitCode: $output")
}
}
return output
}
Benefits
- Better user experience with actionable error messages
- Easier troubleshooting
- Consistent error handling with Retrofit implementation
- Graceful handling of authentication issues
Priority
High - Improves user experience significantly
Related Files
src/main/kotlin/dev/hossain/githubstats/client/GhCliApiClient.kt
src/main/kotlin/dev/hossain/githubstats/util/ErrorProcessor.kt
Problem
Currently,
GhCliApiClient.executeCommand()throws a genericRuntimeExceptionfor all errors:This doesn't distinguish between:
gh auth loginneeded)Proposed Solution
GhCliNotAuthenticatedExceptionGhCliRateLimitExceptionGhCliNetworkExceptionErrorProcessorExample:
Benefits
Priority
High - Improves user experience significantly
Related Files
src/main/kotlin/dev/hossain/githubstats/client/GhCliApiClient.ktsrc/main/kotlin/dev/hossain/githubstats/util/ErrorProcessor.kt