From f49045bae81d2336b7d9b25863909043efea7155 Mon Sep 17 00:00:00 2001 From: LeanBitLab <245915690+LeanBitLab@users.noreply.github.com> Date: Thu, 28 May 2026 19:04:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20Add=20logging=20to=20empty=20cat?= =?UTF-8?q?ch=20blocks=20in=20MainActivity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🎯 What: Replaced multiple empty catch blocks (catch e: Exception {}) with Log.e statements in MainActivity.kt, and added the necessary android.util.Log import. 💡 Why: Swallowing exceptions silently makes debugging issues (like failing to launch settings, failing to open F-Droid links, or Snackbar display issues) incredibly difficult. Logging these exceptions improves maintainability and observability without changing app behavior. ✅ Verification: Project builds successfully, and unit tests pass. Manual review confirms Log.e is safely used in previously silent catch blocks. ✨ Result: Exceptions are now appropriately logged to Logcat instead of being silently ignored, making troubleshooting much easier. --- .../java/com/leanbitlab/lwidget/MainActivity.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt b/app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt index 449d9ae..a948f16 100644 --- a/app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt +++ b/app/src/main/java/com/leanbitlab/lwidget/MainActivity.kt @@ -17,6 +17,7 @@ package com.leanbitlab.lwidget +import android.util.Log import android.Manifest import android.appwidget.AppWidgetManager import android.content.ComponentName @@ -271,10 +272,10 @@ class MainActivity : AppCompatActivity() { } else openAppSettings() } updatePermissionToggle(R.id.row_perm_data_usage, "Data Usage", !usageMissing) { - try { startActivity(Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS)) } catch (e: Exception) {} + try { startActivity(Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS)) } catch (e: Exception) { Log.e("MainActivity", "Failed to open settings", e) } } updatePermissionToggle(R.id.row_perm_screen_time, "Screen Time", !usageMissing) { - try { startActivity(Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS)) } catch (e: Exception) {} + try { startActivity(Intent(android.provider.Settings.ACTION_USAGE_ACCESS_SETTINGS)) } catch (e: Exception) { Log.e("MainActivity", "Failed to open settings", e) } } updatePermissionToggle(R.id.row_perm_weather, "Weather", !weatherMissing) { if (weatherMissing && !isAppInstalled("org.breezyweather")) { @@ -283,7 +284,7 @@ class MainActivity : AppCompatActivity() { } catch (e: Exception) { try { CustomTabsIntent.Builder().build().launchUrl(this@MainActivity, android.net.Uri.parse("https://f-droid.org/packages/org.breezyweather/")) - } catch (e2: Exception) {} + } catch (e2: Exception) { Log.e("MainActivity", "Failed to open link", e2) } } } else if (weatherMissing) { ActivityCompat.requestPermissions(this, arrayOf("org.breezyweather.READ_PROVIDER"), 104) @@ -955,7 +956,7 @@ class MainActivity : AppCompatActivity() { ).setAction("Install") { try { CustomTabsIntent.Builder().build().launchUrl(this@MainActivity, android.net.Uri.parse("https://github.com/breezy-weather/breezy-weather/releases")) - } catch (e: Exception) {} + } catch (e: Exception) { Log.e("MainActivity", "Failed to open release link", e) } }.show() return@setOnCheckedChangeListener } @@ -1011,7 +1012,7 @@ class MainActivity : AppCompatActivity() { getString(R.string.perm_usage_access_title), com.google.android.material.snackbar.Snackbar.LENGTH_LONG ).show() - } catch (e: Exception) {} + } catch (e: Exception) { Log.e("MainActivity", "Failed to show Snackbar", e) } return@setOnCheckedChangeListener } if (!checkLimit()) { @@ -1126,7 +1127,7 @@ class MainActivity : AppCompatActivity() { getString(R.string.perm_usage_access_title), com.google.android.material.snackbar.Snackbar.LENGTH_LONG ).show() - } catch (e: Exception) {} + } catch (e: Exception) { Log.e("MainActivity", "Failed to show Snackbar", e) } return@setOnCheckedChangeListener } if (!checkLimit()) {