From 4554c9d0df9d1690f4d739030f35b7926d19f453 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 17 Nov 2021 17:42:50 +0200 Subject: [PATCH] catch and show hwi enumerate errors --- .../java/com/sparrowwallet/sparrow/io/Hwi.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java index 2edf69c1..487beab0 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/Hwi.java @@ -39,6 +39,7 @@ public class Hwi { private static boolean isPromptActive = false; public List enumerate(String passphrase) throws ImportException { + String output = null; try { List command; if(passphrase != null && !passphrase.isEmpty()) { @@ -48,7 +49,7 @@ public class Hwi { } isPromptActive = true; - String output = execute(command); + output = execute(command); Device[] devices = getGson().fromJson(output, Device[].class); if(devices == null) { throw new ImportException("Error scanning, check devices are ready"); @@ -56,7 +57,19 @@ public class Hwi { return Arrays.stream(devices).filter(device -> device != null && device.getModel() != null).collect(Collectors.toList()); } catch(IOException e) { log.error("Error executing " + HWI_VERSION_DIR, e); - throw new ImportException(e); + throw new ImportException("Error executing HWI", e); + } catch(Exception e) { + if(output != null) { + try { + JsonObject result = JsonParser.parseString(output).getAsJsonObject(); + JsonElement error = result.get("error"); + throw new ImportException(error.getAsString()); + } catch(Exception ex) { + log.error("Error parsing JSON: " + output, e); + throw new ImportException("Error parsing JSON: " + output, e); + } + } + throw e; } finally { isPromptActive = false; }