From 9f861096acea36599d0e5943d0204da5eae91807 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 26 Jul 2018 19:35:54 +0200 Subject: config: show more informative error message on wrong key Signed-off-by: Jason A. Donenfeld --- .../main/java/com/wireguard/android/fragment/TunnelListFragment.java | 2 +- app/src/main/java/com/wireguard/config/Attribute.java | 1 + app/src/main/java/com/wireguard/config/Interface.java | 2 ++ app/src/main/java/com/wireguard/config/Peer.java | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) (limited to 'app/src/main/java') 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 7258f0a0..53c6d612 100644 --- a/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java +++ b/app/src/main/java/com/wireguard/android/fragment/TunnelListFragment.java @@ -85,7 +85,7 @@ public class TunnelListFragment extends BaseFragment { final FragmentManager fragmentManager = getFragmentManager(); if (fragmentManager != null) ConfigNamingDialogFragment.newInstance(configText).show(fragmentManager, null); - } catch (final IllegalArgumentException|IOException exception) { + } catch (final Exception exception) { onTunnelImportFinished(Collections.emptyList(), Collections.singletonList(exception)); } } diff --git a/app/src/main/java/com/wireguard/config/Attribute.java b/app/src/main/java/com/wireguard/config/Attribute.java index b35df100..be068e80 100644 --- a/app/src/main/java/com/wireguard/config/Attribute.java +++ b/app/src/main/java/com/wireguard/config/Attribute.java @@ -55,6 +55,7 @@ public enum Attribute { return TextUtils.join(", ", iterable); } + @Nullable public static Attribute match(final CharSequence line) { return KEY_MAP.get(SEPARATOR_PATTERN.split(line)[0].toLowerCase()); } diff --git a/app/src/main/java/com/wireguard/config/Interface.java b/app/src/main/java/com/wireguard/config/Interface.java index 6560b764..eea1d18b 100644 --- a/app/src/main/java/com/wireguard/config/Interface.java +++ b/app/src/main/java/com/wireguard/config/Interface.java @@ -140,6 +140,8 @@ public class Interface { public void parse(final String line) { final Attribute key = Attribute.match(line); + if (key == null) + throw new IllegalArgumentException(String.format("Unable to parse line: \"%s\"", line)); switch (key) { case ADDRESS: addAddresses(key.parseList(line)); diff --git a/app/src/main/java/com/wireguard/config/Peer.java b/app/src/main/java/com/wireguard/config/Peer.java index 2a4f4465..49c8b70e 100644 --- a/app/src/main/java/com/wireguard/config/Peer.java +++ b/app/src/main/java/com/wireguard/config/Peer.java @@ -113,6 +113,8 @@ public class Peer { public void parse(final String line) { final Attribute key = Attribute.match(line); + if (key == null) + throw new IllegalArgumentException(String.format("Unable to parse line: \"%s\"", line)); switch (key) { case ALLOWED_IPS: addAllowedIPs(key.parseList(line)); -- cgit v1.2.3