From 11aafac91591ee861b9395d307391a55cebc6fd7 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Thu, 16 Dec 2021 15:35:07 -0500 Subject: [PATCH] remove re-throws of exceptions, which clear the stack trace (#1760) * remove re-throws of exceptions, which clear the stack trace * remove whitespace --- .../DatabaseMigrationHostedService.cs | 2 +- src/Billing/Controllers/StripeController.cs | 4 ++-- .../TableStorage/InstallationDeviceRepository.cs | 7 ++----- .../TableStorage/MetaDataRepository.cs | 7 ++----- .../AmazonSesMailDeliveryService.cs | 2 +- .../NotificationHubPushRegistrationService.cs | 14 ++++---------- .../Implementations/StripePaymentService.cs | 12 ++++++------ util/Setup/Program.cs | 2 +- 8 files changed, 19 insertions(+), 31 deletions(-) diff --git a/src/Admin/HostedServices/DatabaseMigrationHostedService.cs b/src/Admin/HostedServices/DatabaseMigrationHostedService.cs index 4c3cb2610d..c507be0656 100644 --- a/src/Admin/HostedServices/DatabaseMigrationHostedService.cs +++ b/src/Admin/HostedServices/DatabaseMigrationHostedService.cs @@ -46,7 +46,7 @@ namespace Bit.Admin.HostedServices if (i >= maxMigrationAttempts) { _logger.LogError(e, "Database failed to migrate."); - throw e; + throw; } else { diff --git a/src/Billing/Controllers/StripeController.cs b/src/Billing/Controllers/StripeController.cs index fb8b9deadc..7f77d7f6be 100644 --- a/src/Billing/Controllers/StripeController.cs +++ b/src/Billing/Controllers/StripeController.cs @@ -603,7 +603,7 @@ namespace Bit.Billing.Controllers } else { - throw e; + throw; } } @@ -698,7 +698,7 @@ namespace Bit.Billing.Controllers } else { - throw e; + throw; } } diff --git a/src/Core/Repositories/TableStorage/InstallationDeviceRepository.cs b/src/Core/Repositories/TableStorage/InstallationDeviceRepository.cs index 81b1632735..828b3366e1 100644 --- a/src/Core/Repositories/TableStorage/InstallationDeviceRepository.cs +++ b/src/Core/Repositories/TableStorage/InstallationDeviceRepository.cs @@ -79,12 +79,9 @@ namespace Bit.Core.Repositories.TableStorage entity.ETag = "*"; await _table.ExecuteAsync(TableOperation.Delete(entity)); } - catch (StorageException e) + catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound) { - if (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound) - { - throw e; - } + throw; } } } diff --git a/src/Core/Repositories/TableStorage/MetaDataRepository.cs b/src/Core/Repositories/TableStorage/MetaDataRepository.cs index 64f3cd23fd..86721128b0 100644 --- a/src/Core/Repositories/TableStorage/MetaDataRepository.cs +++ b/src/Core/Repositories/TableStorage/MetaDataRepository.cs @@ -88,12 +88,9 @@ namespace Bit.Core.Repositories.TableStorage ETag = "*" })); } - catch (StorageException e) + catch (StorageException e) when (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound) { - if (e.RequestInformation.HttpStatusCode != (int)HttpStatusCode.NotFound) - { - throw e; - } + throw; } } } diff --git a/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs b/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs index 41d682b72d..371ee5cc55 100644 --- a/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs +++ b/src/Core/Services/Implementations/AmazonSesMailDeliveryService.cs @@ -130,7 +130,7 @@ namespace Bit.Core.Services { _logger.LogWarning(e, "Failed to send email. Retrying..."); await SendAsync(request, true); - throw e; + throw; } } diff --git a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs index 7822cf6da3..59873ac81f 100644 --- a/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs +++ b/src/Core/Services/Implementations/NotificationHubPushRegistrationService.cs @@ -133,12 +133,9 @@ namespace Bit.Core.Services await _installationDeviceRepository.DeleteAsync(new InstallationDeviceEntity(deviceId)); } } - catch (Exception e) + catch (Exception e) when (e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found")) { - if (e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found")) - { - throw e; - } + throw; } } @@ -192,12 +189,9 @@ namespace Bit.Core.Services { await _client.PatchInstallationAsync(id, new List { operation }); } - catch (Exception e) + catch (Exception e) when (e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found")) { - if (e.InnerException == null || !e.InnerException.Message.Contains("(404) Not Found")) - { - throw e; - } + throw; } } } diff --git a/src/Core/Services/Implementations/StripePaymentService.cs b/src/Core/Services/Implementations/StripePaymentService.cs index e891235c5e..1a5d91dc94 100644 --- a/src/Core/Services/Implementations/StripePaymentService.cs +++ b/src/Core/Services/Implementations/StripePaymentService.cs @@ -171,7 +171,7 @@ namespace Bit.Core.Services { await _btGateway.Customer.DeleteAsync(braintreeCustomer.Id); } - throw e; + throw; } org.Gateway = GatewayType.Stripe; @@ -367,7 +367,7 @@ namespace Bit.Core.Services var message = e.Message.ToLowerInvariant(); if (message.Contains("apple") || message.Contains("in-app")) { - throw e; + throw; } } } @@ -692,7 +692,7 @@ namespace Bit.Core.Services throw new GatewayException("Bank account is not yet verified."); } - throw e; + throw; } } @@ -1105,7 +1105,7 @@ namespace Bit.Core.Services { if (e.Message != $"No such subscription: {subscriber.GatewaySubscriptionId}") { - throw e; + throw; } } } @@ -1408,13 +1408,13 @@ namespace Bit.Core.Services }); } } - catch (Exception e) + catch { if (braintreeCustomer != null && !hadBtCustomer) { await _btGateway.Customer.DeleteAsync(braintreeCustomer.Id); } - throw e; + throw; } return createdCustomer; diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index 470da98450..e41b65f4df 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -213,7 +213,7 @@ namespace Bit.Setup MigrateDatabase(nextAttempt); return; } - throw e; + throw; } }