diff options
author | Samuel Holland <samuel@sholland.org> | 2018-12-15 14:45:14 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-12-15 14:46:23 -0600 |
commit | 2e8d566bd42ac747ad276eb5e328ee2303c48c26 (patch) | |
tree | 50cd35a1bc93e6668a9db982af50b7e5b70c6e1e /app/src/main/java/com/wireguard/android/fragment | |
parent | dcb0e9b3e8643bc73a67c874b9add72cc0ee8f6e (diff) |
Clean up error messages
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/src/main/java/com/wireguard/android/fragment')
5 files changed, 23 insertions, 20 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java index 20633c3e..49cb51ee 100644 --- a/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/AppListDialogFragment.java @@ -22,7 +22,7 @@ import com.wireguard.android.Application; import com.wireguard.android.R; import com.wireguard.android.databinding.AppListDialogFragmentBinding; import com.wireguard.android.model.ApplicationData; -import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.android.util.ErrorMessages; import com.wireguard.android.util.ObservableKeyedArrayList; import com.wireguard.android.util.ObservableKeyedList; @@ -73,7 +73,7 @@ public class AppListDialogFragment extends DialogFragment { appData.clear(); appData.addAll(data); } else { - final String error = throwable != null ? ExceptionLoggers.unwrapMessage(throwable) : "Unknown"; + final String error = ErrorMessages.get(throwable); final String message = activity.getString(R.string.error_fetching_apps, error); Toast.makeText(activity, message, Toast.LENGTH_LONG).show(); dismissAllowingStateLoss(); diff --git a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java index e3003f2e..3b2199aa 100644 --- a/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/BaseFragment.java @@ -25,7 +25,7 @@ import com.wireguard.android.databinding.TunnelDetailFragmentBinding; import com.wireguard.android.databinding.TunnelListItemBinding; import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel.State; -import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.android.util.ErrorMessages; /** * Base class for fragments that need to know the currently-selected tunnel. Only does anything when @@ -111,7 +111,7 @@ public abstract class BaseFragment extends Fragment implements OnSelectedTunnelC tunnel.setState(State.of(checked)).whenComplete((state, throwable) -> { if (throwable == null) return; - final String error = ExceptionLoggers.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); final int messageResId = checked ? R.string.error_up : R.string.error_down; final String message = getContext().getString(messageResId, error); final View view = getView(); diff --git a/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java b/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java index 2cdf79ae..e56b4286 100644 --- a/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/ConfigNamingDialogFragment.java @@ -27,8 +27,8 @@ import java.nio.charset.StandardCharsets; import java.util.Objects; public class ConfigNamingDialogFragment extends DialogFragment { - private static final String KEY_CONFIG_TEXT = "config_text"; + @Nullable private ConfigNamingDialogFragmentBinding binding; @Nullable private Config config; @Nullable private InputMethodManager imm; @@ -65,23 +65,26 @@ public class ConfigNamingDialogFragment extends DialogFragment { public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); + final Bundle arguments = getArguments(); + final String configText = arguments.getString(KEY_CONFIG_TEXT); + final byte[] configBytes = configText.getBytes(StandardCharsets.UTF_8); try { - config = Config.parse(new ByteArrayInputStream(getArguments().getString(KEY_CONFIG_TEXT).getBytes(StandardCharsets.UTF_8))); + config = Config.parse(new ByteArrayInputStream(configBytes)); } catch (final BadConfigException | IOException e) { - throw new RuntimeException(getResources().getString(R.string.invalid_config_error, getClass().getSimpleName()), e); + throw new IllegalArgumentException("Invalid config passed to " + getClass().getSimpleName(), e); } } @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { - final Activity activity = getActivity(); + final Activity activity = Objects.requireNonNull(getActivity()); - imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); + imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); - alertDialogBuilder.setTitle(R.string.import_from_qrcode); + alertDialogBuilder.setTitle(R.string.import_from_qr_code); - binding = ConfigNamingDialogFragmentBinding.inflate(getActivity().getLayoutInflater(), null, false); + binding = ConfigNamingDialogFragmentBinding.inflate(activity.getLayoutInflater(), null, false); binding.executePendingBindings(); alertDialogBuilder.setView(binding.getRoot()); diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java index f1250e64..7c4a162a 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelEditorFragment.java @@ -28,7 +28,7 @@ import com.wireguard.android.databinding.TunnelEditorFragmentBinding; import com.wireguard.android.fragment.AppListDialogFragment.AppExclusionListener; import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.TunnelManager; -import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.android.util.ErrorMessages; import com.wireguard.android.viewmodel.ConfigProxy; import com.wireguard.config.Config; @@ -63,7 +63,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show(); onFinished(); } else { - final String error = ExceptionLoggers.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); message = getString(R.string.config_save_error, savedTunnel.getName(), error); Log.e(TAG, message, throwable); if (binding != null) { @@ -140,7 +140,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi try { newConfig = binding.getConfig().resolve(); } catch (final Exception e) { - final String error = ExceptionLoggers.unwrapMessage(e); + final String error = ErrorMessages.get(e); final String tunnelName = tunnel == null ? binding.getName() : tunnel.getName(); final String message = getString(R.string.config_save_error, tunnelName, error); Log.e(TAG, message, e); @@ -208,7 +208,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show(); onFinished(); } else { - final String error = ExceptionLoggers.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); message = getString(R.string.tunnel_create_error, error); Log.e(TAG, message, throwable); if (binding != null) { @@ -227,7 +227,7 @@ public class TunnelEditorFragment extends BaseFragment implements AppExclusionLi 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.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); message = getString(R.string.tunnel_rename_error, error); Log.e(TAG, message, throwable); if (binding != null) { diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java index 4a6103ba..5871f262 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -37,7 +37,7 @@ import com.wireguard.android.databinding.ObservableKeyedRecyclerViewAdapter; import com.wireguard.android.databinding.TunnelListFragmentBinding; import com.wireguard.android.databinding.TunnelListItemBinding; import com.wireguard.android.model.Tunnel; -import com.wireguard.android.util.ExceptionLoggers; +import com.wireguard.android.util.ErrorMessages; import com.wireguard.android.widget.MultiselectableRelativeLayout; import com.wireguard.android.widget.fab.FloatingActionsMenuRecyclerViewScrollListener; import com.wireguard.config.BadConfigException; @@ -270,7 +270,7 @@ public class TunnelListFragment extends BaseFragment { final IntentIntegrator intentIntegrator = IntentIntegrator.forSupportFragment(this); intentIntegrator.setOrientationLocked(false); intentIntegrator.setBeepEnabled(false); - intentIntegrator.setPrompt(getString(R.string.qrcode_hint)); + intentIntegrator.setPrompt(getString(R.string.qr_code_hint)); intentIntegrator.initiateScan(Collections.singletonList(IntentIntegrator.QR_CODE)); if (binding != null) @@ -301,7 +301,7 @@ public class TunnelListFragment extends BaseFragment { if (throwable == null) { message = getResources().getQuantityString(R.plurals.delete_success, count, count); } else { - final String error = ExceptionLoggers.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); message = getResources().getQuantityString(R.plurals.delete_error, count, count, error); Log.e(TAG, message, throwable); } @@ -314,7 +314,7 @@ public class TunnelListFragment extends BaseFragment { String message = null; for (final Throwable throwable : throwables) { - final String error = ExceptionLoggers.unwrapMessage(throwable); + final String error = ErrorMessages.get(throwable); message = getString(R.string.import_error, error); Log.e(TAG, message, throwable); } |