From 4eb59b11f0ef2a4122bc313e07f411adc40d3056 Mon Sep 17 00:00:00 2001
From: pacien
Date: Sat, 26 May 2018 13:23:38 +0200
Subject: Catch and display all startup exceptions
---
app/src/main/java/org/pacien/tincapp/extensions/Java.kt | 2 ++
.../java/org/pacien/tincapp/service/TincVpnService.kt | 17 +++++++++++------
app/src/main/res/values/strings.xml | 2 ++
3 files changed, 15 insertions(+), 6 deletions(-)
(limited to 'app/src/main')
diff --git a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt
index 95fecbf..e51e9db 100644
--- a/app/src/main/java/org/pacien/tincapp/extensions/Java.kt
+++ b/app/src/main/java/org/pacien/tincapp/extensions/Java.kt
@@ -15,4 +15,6 @@ object Java {
alt
}
+ fun Throwable.defaultMessage() = this.message ?: "null"
+
}
diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
index 69811f4..ec3e774 100644
--- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
+++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt
@@ -18,6 +18,7 @@ import org.pacien.tincapp.context.AppPaths
import org.pacien.tincapp.data.TincConfiguration
import org.pacien.tincapp.data.VpnInterfaceConfiguration
import org.pacien.tincapp.extensions.Java.applyIgnoringException
+import org.pacien.tincapp.extensions.Java.defaultMessage
import org.pacien.tincapp.extensions.VpnServiceBuilder.applyCfg
import org.pacien.tincapp.intent.Actions
import org.pacien.tincapp.utils.TincKeyring
@@ -75,9 +76,11 @@ class TincVpnService : VpnService() {
val interfaceCfg = try {
VpnInterfaceConfiguration.fromIfaceConfiguration(AppPaths.existing(AppPaths.netConfFile(netName)))
} catch (e: FileNotFoundException) {
- return reportError(resources.getString(R.string.message_network_config_not_found_format, e.message!!), e, "configuration")
+ return reportError(resources.getString(R.string.message_network_config_not_found_format, e.defaultMessage()), e, "configuration")
} catch (e: ConversionException) {
- return reportError(resources.getString(R.string.message_network_config_invalid_format, e.message!!), e, "network-interface")
+ return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
+ } catch (e: Exception) {
+ return reportError(resources.getString(R.string.message_could_not_read_network_configuration_format, e.defaultMessage()), e)
}
val deviceFd = try {
@@ -86,11 +89,11 @@ class TincVpnService : VpnService() {
.also { applyIgnoringException(it::addDisallowedApplication, BuildConfig.APPLICATION_ID) }
.establish()!!
} catch (e: IllegalArgumentException) {
- return reportError(resources.getString(R.string.message_network_config_invalid_format, e.message!!), e, "network-interface")
- } catch (e: IllegalStateException) {
- return reportError(resources.getString(R.string.message_could_not_configure_iface, e.message!!), e)
+ return reportError(resources.getString(R.string.message_network_config_invalid_format, e.defaultMessage()), e, "network-interface")
} catch (e: NullPointerException) {
return reportError(resources.getString(R.string.message_could_not_bind_iface), e)
+ } catch (e: Exception) {
+ return reportError(resources.getString(R.string.message_could_not_configure_iface, e.defaultMessage()), e)
}
val privateKeys = try {
@@ -103,6 +106,8 @@ class TincVpnService : VpnService() {
Pair(null, null)
} catch (e: PEMException) {
return reportError(resources.getString(R.string.message_could_not_decrypt_private_keys_format, e.message))
+ } catch (e: Exception) {
+ return reportError(resources.getString(R.string.message_could_not_read_private_key_format, e.defaultMessage()), e)
}
val daemon = Tincd.start(netName, deviceFd.fd, privateKeys.first?.fd, privateKeys.second?.fd)
@@ -114,7 +119,7 @@ class TincVpnService : VpnService() {
privateKeys.second?.close()
if (exception != null) {
- reportError(resources.getString(R.string.message_daemon_exited, exception.cause!!.message!!), exception)
+ reportError(resources.getString(R.string.message_daemon_exited, exception.cause!!.defaultMessage()), exception)
} else {
logger?.info("tinc daemon started.")
broadcastEvent(Actions.EVENT_CONNECTED)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6ff9ab5..6ac776f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -96,6 +96,8 @@
The application has previously encountered a fatal error.
The crash details have been saved in \"%1$s\".
No running tinc daemon has been found.
+ Could not read network interface configuration:\n\n%1$s
+ Could not read tinc private keys:\n\n%1$s
none
yes
--
cgit v1.2.3