Implement DisplayAddress's Error handling.
MODIFY
WalletWasabi.Tests/HwiTests/NoConnectedDeviceTests.cs
WalletWasabi.Tests/HwiTests/NoConnectedDeviceTests.cs
@@ -79,6 +79,8 @@ namespace WalletWasabi.Tests.HwiTests
await Assert.ThrowsAsync<OperationCanceledException>(async () => await client.GetVersionAsync(cts.Token));
await Assert.ThrowsAsync<OperationCanceledException>(async () => await client.GetHelpAsync(cts.Token));
await Assert.ThrowsAsync<OperationCanceledException>(async () => await client.EnumerateAsync(cts.Token));
+ await Assert.ThrowsAsync<OperationCanceledException>(async () => await client.SetupAsync(cts.Token));
+ await Assert.ThrowsAsync<OperationCanceledException>(async () => await client.DisplayAddressAsync(cts.Token));
}
}
@@ -97,7 +99,9 @@ namespace WalletWasabi.Tests.HwiTests
client.EnumerateAsync(cts.Token),
client.EnumerateAsync(cts.Token),
client.SetupAsync(cts.Token),
- client.SetupAsync(cts.Token)
+ client.SetupAsync(cts.Token),
+ client.DisplayAddressAsync(cts.Token),
+ client.DisplayAddressAsync(cts.Token)
};
cts.CancelAfter(ReasonableRequestTimeout * tasks.Count);
@@ -108,12 +112,17 @@ namespace WalletWasabi.Tests.HwiTests
[Theory]
[MemberData(nameof(GetHwiClientConfigurationCombinationValues))]
- public async Task SetupThrowsHwiExceptionAsync(HwiClient client)
+ public async Task ThrowsHwiExceptionsAsync(HwiClient client)
{
using (var cts = new CancellationTokenSource(ReasonableRequestTimeout))
{
await Assert.ThrowsAsync<HwiException>(async () => await client.SetupAsync(cts.Token));
}
+
+ using (var cts = new CancellationTokenSource(ReasonableRequestTimeout))
+ {
+ await Assert.ThrowsAsync<HwiException>(async () => await client.DisplayAddressAsync(cts.Token));
+ }
}
#endregion Tests

MODIFY
WalletWasabi/Hwi2/HwiClient.cs
WalletWasabi/Hwi2/HwiClient.cs
@@ -55,17 +55,17 @@ namespace WalletWasabi.Hwi2
{
await process.WaitForExitAsync(cancel).ConfigureAwait(false);
+ string responseString = await process.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
if (process.ExitCode != 0)
{
- throw new IOException($"'hwi {arguments}' exited with incorrect exit code.", process.ExitCode);
+ ThrowIfError(responseString);
+ throw new HwiException(HwiErrorCode.UnknownError, $"'hwi {arguments}' exited with incorrect exit code: {process.ExitCode}.");
}
- string responseString = await process.StandardOutput.ReadToEndAsync().ConfigureAwait(false);
+ ThrowIfError(responseString);
if (JsonHelpers.TryParseJToken(responseString, out JToken responseJToken))
{
- ThrowIfError(responseJToken);
-
return responseString;
}
else
@@ -127,6 +127,12 @@ namespace WalletWasabi.Hwi2
return responseString;
}
+ public async Task<string> DisplayAddressAsync(CancellationToken cancel)
+ {
+ string responseString = await SendCommandAsync(options: null, command: HwiCommands.DisplayAddress, cancel).ConfigureAwait(false);
+ return responseString;
+ }
+
#endregion Commands
#region Helpers
@@ -145,7 +151,9 @@ namespace WalletWasabi.Hwi2
return false;
}
- private static void ThrowIfError(JToken responseJToken)
+ private static void ThrowIfError(string responseString)
+ {
+ if (JsonHelpers.TryParseJToken(responseString, out JToken responseJToken))
{
if (responseJToken.HasValues)
{
@@ -176,6 +184,17 @@ namespace WalletWasabi.Hwi2
}
}
}
+ else
+ {
+ var subString = "error:";
+ if (responseString.Contains(subString, StringComparison.OrdinalIgnoreCase))
+ {
+ int startIndex = responseString.IndexOf(subString, StringComparison.OrdinalIgnoreCase) + subString.Length;
+ var err = responseString.Substring(startIndex);
+ throw new HwiException(HwiErrorCode.UnknownError, err);
+ }
+ }
+ }
private static string GetHwiPath()
{

Implement DisplayAddress's Error handling.