Unify the usage of OperationCanceledException, TaskCanceledException and TimeoutException.
MODIFY
WalletWasabi.Gui/Controls/WalletExplorer/TransactionViewModel.cs
WalletWasabi.Gui/Controls/WalletExplorer/TransactionViewModel.cs
@@ -80,13 +80,14 @@ namespace WalletWasabi.Gui.Controls.WalletExplorer
await Task.Delay(1000, cancelToken);
ClipboardNotificationVisible = false;
}
- catch (Exception ex)
- {
- if (ex is OperationCanceledException || ex is TaskCanceledException)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
- return;
+ Logging.Logger.LogTrace<AddressViewModel>(ex);
}
-
+ catch (Exception ex)
+ {
Logging.Logger.LogWarning<AddressViewModel>(ex);
}
finally

MODIFY
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
WalletWasabi.Gui/ViewModels/AddressViewModel.cs
@@ -108,13 +108,14 @@ namespace WalletWasabi.Gui.ViewModels
await Task.Delay(1000, cancelToken);
ClipboardNotificationVisible = false;
}
- catch (Exception ex)
- {
- if (ex is OperationCanceledException || ex is TaskCanceledException)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
- return;
+ Logging.Logger.LogTrace<AddressViewModel>(ex);
}
-
+ catch (Exception ex)
+ {
Logging.Logger.LogWarning<AddressViewModel>(ex);
}
finally

MODIFY
WalletWasabi/Services/MemPoolService.cs
WalletWasabi/Services/MemPoolService.cs
@@ -102,21 +102,18 @@ namespace WalletWasabi.Services
allTxs.UnionWith(txs);
if (cancel.IsCancellationRequested) return false;
}
- catch (Exception ex)
- {
- if ((ex is InvalidOperationException && ex.Message.StartsWith("The node is not in a connected state", StringComparison.InvariantCultureIgnoreCase))
+ catch (Exception ex) when ((ex is InvalidOperationException && ex.Message.StartsWith("The node is not in a connected state", StringComparison.InvariantCultureIgnoreCase))
|| ex is OperationCanceledException
|| ex is TaskCanceledException
|| ex is TimeoutException)
{
Logger.LogTrace<MemPoolService>(ex);
}
- else
+ catch (Exception ex)
{
Logger.LogDebug<MemPoolService>(ex);
}
}
- }
uint256[] toRemove = TransactionHashes.Except(allTxs).ToArray();
foreach (uint256 tx in toRemove)
@@ -127,19 +124,16 @@ namespace WalletWasabi.Services
return true;
}
- catch (Exception ex)
- {
- if (ex is OperationCanceledException
+ catch (Exception ex) when (ex is OperationCanceledException
|| ex is TaskCanceledException
|| ex is TimeoutException)
{
Logger.LogTrace<MemPoolService>(ex);
}
- else
+ catch (Exception ex)
{
Logger.LogDebug<MemPoolService>(ex);
}
- }
finally
{
Interlocked.Exchange(ref _cleanupInProcess, 0);

MODIFY
WalletWasabi/Services/UpdateChecker.cs
WalletWasabi/Services/UpdateChecker.cs
@@ -66,19 +66,18 @@ namespace WalletWasabi.Services
Logger.LogTrace<UpdateChecker>(ex2);
}
}
- catch (Exception ex)
- {
- if (ex is TaskCanceledException || ex is OperationCanceledException || ex is TimeoutException)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
Logger.LogTrace<UpdateChecker>(ex);
}
- else
+ catch (Exception ex)
{
Logger.LogDebug<UpdateChecker>(ex);
}
}
}
- }
finally
{
Interlocked.CompareExchange(ref _running, 3, 2); // If IsStopping, make it stopped.

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -794,13 +794,9 @@ namespace WalletWasabi.Services
node.DisconnectAsync("Thank you!");
}
}
- catch (TimeoutException)
- {
- Logger.LogInfo<WalletService>($"Disconnected node: {node.RemoteSocketAddress}, because block download took too long.");
- node.DisconnectAsync("Block download took too long.");
- continue;
- }
- catch (OperationCanceledException)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
Logger.LogInfo<WalletService>($"Disconnected node: {node.RemoteSocketAddress}, because block download took too long.");
node.DisconnectAsync("Block download took too long.");

MODIFY
WalletWasabi/Services/WasabiSynchronizer.cs
WalletWasabi/Services/WasabiSynchronizer.cs
@@ -387,9 +387,7 @@ namespace WalletWasabi.Services
LastResponse = response;
ResponseArrived?.Invoke(this, response);
}
- catch (Exception ex)
- {
- if (ex is ConnectionException)
+ catch (ConnectionException ex)
{
Logger.LogError<CcjClient>(ex);
try
@@ -401,15 +399,16 @@ namespace WalletWasabi.Services
Logger.LogTrace<CcjClient>(ex2);
}
}
- else if (ex is TaskCanceledException || ex is OperationCanceledException || ex is TimeoutException)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
Logger.LogTrace<WasabiSynchronizer>(ex);
}
- else
+ catch (Exception ex)
{
Logger.LogError<WasabiSynchronizer>(ex);
}
- }
finally
{
if (IsRunning && !ignoreRequestInterval)

MODIFY
WalletWasabi/TorSocks5/TorProcessManager.cs
WalletWasabi/TorSocks5/TorProcessManager.cs
@@ -293,15 +293,9 @@ namespace WalletWasabi.TorSocks5
}
}
}
- catch (TaskCanceledException ex)
- {
- Logger.LogTrace<TorProcessManager>(ex);
- }
- catch (OperationCanceledException ex)
- {
- Logger.LogTrace<TorProcessManager>(ex);
- }
- catch (TimeoutException ex)
+ catch (Exception ex) when (ex is OperationCanceledException
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
Logger.LogTrace<TorProcessManager>(ex);
}

MODIFY
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
WalletWasabi/WebClients/Wasabi/ChaumianCoinJoin/AliceClient.cs
@@ -211,15 +211,9 @@ namespace WalletWasabi.WebClients.Wasabi.ChaumianCoinJoin
}
}
}
- catch (TaskCanceledException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
- {
- return;
- }
- catch (OperationCanceledException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
- {
- return;
- }
- catch (TimeoutException) // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
+ catch (Exception ex) when (ex is OperationCanceledException // If couldn't do it within 3 seconds then it'll likely time out and take it as unconfirmed.
+ || ex is TaskCanceledException
+ || ex is TimeoutException)
{
return;
}

Unify the usage of OperationCanceledException, TaskCanceledException and TimeoutException.