diff options
author | Samuel Holland <samuel@sholland.org> | 2018-12-13 21:30:38 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-12-15 14:46:23 -0600 |
commit | dcb0e9b3e8643bc73a67c874b9add72cc0ee8f6e (patch) | |
tree | e0f720a7315a60827d19daa8ee155f09eab61586 /app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java | |
parent | 3497882ea6ae74ef6da0984a21398963624e9561 (diff) |
Provide semantically meaningful exceptions for translation
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java index f9cadf5f..3cb5ca9f 100644 --- a/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java +++ b/app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java @@ -11,8 +11,9 @@ import android.util.Log; import com.wireguard.android.Application; import com.wireguard.android.R; +import com.wireguard.config.BadConfigException; import com.wireguard.config.ParseException; -import com.wireguard.crypto.Key; +import com.wireguard.crypto.KeyFormatException; import java9.util.concurrent.CompletionException; import java9.util.function.BiConsumer; @@ -37,6 +38,8 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> { public static Throwable unwrap(final Throwable throwable) { if (throwable instanceof CompletionException && throwable.getCause() != null) return throwable.getCause(); + if (throwable instanceof ParseException && throwable.getCause() != null) + return throwable.getCause(); return throwable; } @@ -44,13 +47,14 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> { final Throwable innerThrowable = unwrap(throwable); final Resources resources = Application.get().getResources(); String message; - if (innerThrowable instanceof ParseException) { - final ParseException parseException = (ParseException) innerThrowable; - message = resources.getString(R.string.parse_error, parseException.getText(), parseException.getContext()); - if (parseException.getMessage() != null) - message += ": " + parseException.getMessage(); - } else if (innerThrowable instanceof Key.KeyFormatException) { - final Key.KeyFormatException keyFormatException = (Key.KeyFormatException) innerThrowable; + if (innerThrowable instanceof BadConfigException) { + final BadConfigException configException = (BadConfigException) innerThrowable; + message = resources.getString(R.string.parse_error, configException.getText(), configException.getLocation()); + final Throwable cause = unwrap(configException); + if (cause.getMessage() != null) + message += ": " + cause.getMessage(); + } else if (innerThrowable instanceof KeyFormatException) { + final KeyFormatException keyFormatException = (KeyFormatException) innerThrowable; switch (keyFormatException.getFormat()) { case BASE64: message = resources.getString(R.string.key_length_base64_exception_message); |