mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
catch and show hwi enumerate errors
This commit is contained in:
parent
9b9b295045
commit
4554c9d0df
1 changed files with 15 additions and 2 deletions
|
@ -39,6 +39,7 @@ public class Hwi {
|
||||||
private static boolean isPromptActive = false;
|
private static boolean isPromptActive = false;
|
||||||
|
|
||||||
public List<Device> enumerate(String passphrase) throws ImportException {
|
public List<Device> enumerate(String passphrase) throws ImportException {
|
||||||
|
String output = null;
|
||||||
try {
|
try {
|
||||||
List<String> command;
|
List<String> command;
|
||||||
if(passphrase != null && !passphrase.isEmpty()) {
|
if(passphrase != null && !passphrase.isEmpty()) {
|
||||||
|
@ -48,7 +49,7 @@ public class Hwi {
|
||||||
}
|
}
|
||||||
|
|
||||||
isPromptActive = true;
|
isPromptActive = true;
|
||||||
String output = execute(command);
|
output = execute(command);
|
||||||
Device[] devices = getGson().fromJson(output, Device[].class);
|
Device[] devices = getGson().fromJson(output, Device[].class);
|
||||||
if(devices == null) {
|
if(devices == null) {
|
||||||
throw new ImportException("Error scanning, check devices are ready");
|
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());
|
return Arrays.stream(devices).filter(device -> device != null && device.getModel() != null).collect(Collectors.toList());
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log.error("Error executing " + HWI_VERSION_DIR, 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 {
|
} finally {
|
||||||
isPromptActive = false;
|
isPromptActive = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue