Selaa lähdekoodia

ExceptionLoggers: never have a null message

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
master
Jason A. Donenfeld 6 vuotta sitten
vanhempi
commit
694577b9b4
6 muutettua tiedostoa jossa 20 lisäystä ja 11 poistoa
  1. +1
    -1
      app/src/main/java/com/wireguard/android/QuickTileService.java
  2. +1
    -1
      app/src/main/java/com/wireguard/android/fragment/TunnelController.java
  3. +4
    -4
      app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java
  4. +2
    -2
      app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java
  5. +1
    -1
      app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java
  6. +11
    -2
      app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java

+ 1
- 1
app/src/main/java/com/wireguard/android/QuickTileService.java Näytä tiedosto

@@ -76,7 +76,7 @@ public class QuickTileService extends TileService {
final Throwable throwable) {
if (throwable == null)
return;
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
final String message = getString(R.string.toggle_error, error);
Log.e(TAG, message, throwable);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();


+ 1
- 1
app/src/main/java/com/wireguard/android/fragment/TunnelController.java Näytä tiedosto

@@ -48,7 +48,7 @@ public final class TunnelController {
if (throwable == null)
return;
final Context context = view.getContext();
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
final int messageResId = checked ? R.string.error_up : R.string.error_down;
final String message = context.getString(messageResId, error);
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();


+ 4
- 4
app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java Näytä tiedosto

@@ -54,7 +54,7 @@ public class TunnelEditorFragment extends BaseFragment {
Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
onFinished();
} else {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
message = getString(R.string.config_save_error, savedTunnel.getName(), error);
Log.e(TAG, message, throwable);
if (binding != null) {
@@ -119,7 +119,7 @@ public class TunnelEditorFragment extends BaseFragment {
try {
binding.getConfig().commitData(newConfig);
} catch (final Exception e) {
final String error = ExceptionLoggers.unwrap(e).getMessage();
final String error = ExceptionLoggers.unwrapMessage(e);
final String tunnelName = tunnel == null ? binding.getConfig().getName() : tunnel.getName();
final String message = getString(R.string.config_save_error, tunnelName, error);
Log.e(TAG, message, e);
@@ -171,7 +171,7 @@ public class TunnelEditorFragment extends BaseFragment {
Log.d(TAG, message);
onFinished();
} else {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
message = getString(R.string.tunnel_create_error, error);
Log.e(TAG, message, throwable);
if (binding != null) {
@@ -190,7 +190,7 @@ public class TunnelEditorFragment extends BaseFragment {
Log.d(TAG, "Attempting to save config of renamed tunnel " + tunnel.getName());
renamedTunnel.setConfig(newConfig).whenComplete((a, b) -> onConfigSaved(renamedTunnel, b));
} else {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
message = getString(R.string.tunnel_rename_error, error);
Log.e(TAG, message, throwable);
if (binding != null) {


+ 2
- 2
app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java Näytä tiedosto

@@ -239,7 +239,7 @@ public class TunnelListFragment extends BaseFragment {
if (throwable == null) {
message = getResources().getQuantityString(R.plurals.delete_success, count, count);
} else {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
message = getResources().getQuantityString(R.plurals.delete_error, count, count, error);
Log.e(TAG, message, throwable);
}
@@ -252,7 +252,7 @@ public class TunnelListFragment extends BaseFragment {
String message = null;

for (final Throwable throwable : throwables) {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
message = getString(R.string.import_error, error);
Log.e(TAG, message, throwable);
}


+ 1
- 1
app/src/main/java/com/wireguard/android/preference/ZipExporterPreference.java Näytä tiedosto

@@ -102,7 +102,7 @@ public class ZipExporterPreference extends Preference {

private void exportZipComplete(final String filePath, final Throwable throwable) {
if (throwable != null) {
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
final String error = ExceptionLoggers.unwrapMessage(throwable);
final String message = getContext().getString(R.string.export_error, error);
Log.e(TAG, message, throwable);
Snackbar.make(


+ 11
- 2
app/src/main/java/com/wireguard/android/util/ExceptionLoggers.java Näytä tiedosto

@@ -6,8 +6,8 @@

package com.wireguard.android.util;

import android.support.annotation.NonNull;
import android.util.Log;

import java9.util.concurrent.CompletionException;
import java9.util.function.BiConsumer;

@@ -29,11 +29,20 @@ public enum ExceptionLoggers implements BiConsumer<Object, Throwable> {
}

public static Throwable unwrap(final Throwable throwable) {
if (throwable instanceof CompletionException)
if (throwable instanceof CompletionException && throwable.getCause() != null)
return throwable.getCause();
return throwable;
}

@NonNull
public static String unwrapMessage(Throwable throwable) {
throwable = unwrap(throwable);
final String message = throwable.getMessage();
if (message != null)
return message;
return throwable.getClass().getSimpleName();
}

@Override
public void accept(final Object result, final Throwable throwable) {
if (throwable != null)


Ladataan…
Peruuta
Tallenna