From fb70fbb2518ef14692dc3175c37cb49ad3c3081d Mon Sep 17 00:00:00 2001 From: Lucas Pedroza Date: Thu, 4 Jan 2024 13:58:12 +0100 Subject: [PATCH] Remove inner exceptions where not needed --- Fauna.Test/Exceptions/AbortException.Tests.cs | 5 --- .../AuthenticationException.Tests.cs | 13 -------- .../AuthorizationException.Tests.cs | 13 -------- .../ContendedTransactionException.Tests.cs | 13 -------- .../InvalidRequestException.Tests.cs | 13 -------- .../Exceptions/QueryCheckException.Tests.cs | 13 -------- .../Exceptions/QueryRuntimeException.Tests.cs | 13 -------- .../Exceptions/QueryTimeoutException.Tests.cs | 13 -------- .../Exceptions/ServiceException.Tests.cs | 13 -------- .../Exceptions/ThrottlingException.Tests.cs | 13 -------- .../WriteConstraintException.Tests.cs | 13 -------- Fauna/Exceptions/AbortException.cs | 33 +++++++------------ Fauna/Exceptions/AuthenticationException.cs | 5 +-- Fauna/Exceptions/AuthorizationException.cs | 5 +-- .../ContendedTransactionException.cs | 3 -- Fauna/Exceptions/InvalidRequestException.cs | 3 -- Fauna/Exceptions/QueryCheckException.cs | 3 -- Fauna/Exceptions/QueryRuntimeException.cs | 3 -- Fauna/Exceptions/QueryTimeoutException.cs | 3 -- Fauna/Exceptions/ServiceException.cs | 9 ----- Fauna/Exceptions/ThrottlingException.cs | 3 -- Fauna/Exceptions/WriteConstraintException.cs | 3 -- 22 files changed, 13 insertions(+), 195 deletions(-) diff --git a/Fauna.Test/Exceptions/AbortException.Tests.cs b/Fauna.Test/Exceptions/AbortException.Tests.cs index c5f3b6fa..2a59c0e1 100644 --- a/Fauna.Test/Exceptions/AbortException.Tests.cs +++ b/Fauna.Test/Exceptions/AbortException.Tests.cs @@ -24,14 +24,9 @@ public void Ctor_InitializesPropertiesCorrectly() var expectedInnerException = new Exception("Inner exception"); var actual1 = new AbortException(ctx, expectedQueryFailure, expectedMessage); - var actual2 = new AbortException(ctx, expectedQueryFailure, expectedMessage, expectedInnerException); Assert.AreEqual(expectedQueryFailure.ErrorInfo.Abort, actual1.QueryFailure.ErrorInfo.Abort); Assert.AreEqual(expectedMessage, actual1.Message); - - Assert.AreEqual(expectedQueryFailure.ErrorInfo.Abort, actual2.QueryFailure.ErrorInfo.Abort); - Assert.AreEqual(expectedMessage, actual2.Message); - Assert.AreEqual(expectedInnerException, actual2.InnerException); } [Test] diff --git a/Fauna.Test/Exceptions/AuthenticationException.Tests.cs b/Fauna.Test/Exceptions/AuthenticationException.Tests.cs index 71a01a74..9f6118ee 100644 --- a/Fauna.Test/Exceptions/AuthenticationException.Tests.cs +++ b/Fauna.Test/Exceptions/AuthenticationException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("unauthorized"); - var message = "Authentication error"; - var innerException = new Exception("Inner exception"); - var exception = new AuthenticationException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/AuthorizationException.Tests.cs b/Fauna.Test/Exceptions/AuthorizationException.Tests.cs index 516a94a2..34f588aa 100644 --- a/Fauna.Test/Exceptions/AuthorizationException.Tests.cs +++ b/Fauna.Test/Exceptions/AuthorizationException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("forbidden"); - var message = "Authorization error"; - var innerException = new Exception("Inner exception"); - var exception = new AuthorizationException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/ContendedTransactionException.Tests.cs b/Fauna.Test/Exceptions/ContendedTransactionException.Tests.cs index 19d22fcf..014ec6ed 100644 --- a/Fauna.Test/Exceptions/ContendedTransactionException.Tests.cs +++ b/Fauna.Test/Exceptions/ContendedTransactionException.Tests.cs @@ -18,18 +18,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("contended_transaction"); - var message = "Transaction contention occurred"; - var innerException = new Exception("Inner exception"); - var exception = new ContendedTransactionException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/InvalidRequestException.Tests.cs b/Fauna.Test/Exceptions/InvalidRequestException.Tests.cs index 1dddfe0d..d791c09f 100644 --- a/Fauna.Test/Exceptions/InvalidRequestException.Tests.cs +++ b/Fauna.Test/Exceptions/InvalidRequestException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("invalid_request"); - var message = "Invalid request error"; - var innerException = new Exception("Inner exception"); - var exception = new InvalidRequestException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/QueryCheckException.Tests.cs b/Fauna.Test/Exceptions/QueryCheckException.Tests.cs index c69839a0..ef5f0bd7 100644 --- a/Fauna.Test/Exceptions/QueryCheckException.Tests.cs +++ b/Fauna.Test/Exceptions/QueryCheckException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("invalid_query"); - var message = "Query check error"; - var innerException = new Exception("Inner exception"); - var exception = new QueryCheckException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/QueryRuntimeException.Tests.cs b/Fauna.Test/Exceptions/QueryRuntimeException.Tests.cs index cb114cb5..42e6e775 100644 --- a/Fauna.Test/Exceptions/QueryRuntimeException.Tests.cs +++ b/Fauna.Test/Exceptions/QueryRuntimeException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("invalid_argument"); - var message = "Query runtime error"; - var innerException = new Exception("Inner exception"); - var exception = new QueryRuntimeException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/QueryTimeoutException.Tests.cs b/Fauna.Test/Exceptions/QueryTimeoutException.Tests.cs index 1c849f8b..d694c318 100644 --- a/Fauna.Test/Exceptions/QueryTimeoutException.Tests.cs +++ b/Fauna.Test/Exceptions/QueryTimeoutException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("time_limit_exceeded"); - var message = "Query timeout error"; - var innerException = new Exception("Inner exception"); - var exception = new QueryTimeoutException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/ServiceException.Tests.cs b/Fauna.Test/Exceptions/ServiceException.Tests.cs index 26b367be..cab423c0 100644 --- a/Fauna.Test/Exceptions/ServiceException.Tests.cs +++ b/Fauna.Test/Exceptions/ServiceException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("internal_error"); - var message = "Service error"; - var innerException = new Exception("Inner exception"); - var exception = new ServiceException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/ThrottlingException.Tests.cs b/Fauna.Test/Exceptions/ThrottlingException.Tests.cs index d6759cc2..49b8f44f 100644 --- a/Fauna.Test/Exceptions/ThrottlingException.Tests.cs +++ b/Fauna.Test/Exceptions/ThrottlingException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("limit_exceeded"); - var message = "Throttling error occurred"; - var innerException = new Exception("Inner exception"); - var exception = new ThrottlingException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna.Test/Exceptions/WriteConstraintException.Tests.cs b/Fauna.Test/Exceptions/WriteConstraintException.Tests.cs index b4c8d4e3..0ef722de 100644 --- a/Fauna.Test/Exceptions/WriteConstraintException.Tests.cs +++ b/Fauna.Test/Exceptions/WriteConstraintException.Tests.cs @@ -17,18 +17,5 @@ public void CtorWithQueryFailureAndMessage_ShouldSetProperties() Assert.AreEqual(exception.QueryFailure, queryFailure); Assert.AreEqual(exception.Message, message); } - - [Test] - public void CtorWithQueryFailureMessageAndInnerException_ShouldSetProperties() - { - var queryFailure = ExceptionTestHelper.CreateQueryFailure("write_constraint_error"); - var message = "Write constraint error"; - var innerException = new Exception("Inner exception"); - var exception = new WriteConstraintException(queryFailure, message, innerException); - - Assert.AreEqual(exception.QueryFailure, queryFailure); - Assert.AreEqual(exception.Message, message); - Assert.AreEqual(exception.InnerException, innerException); - } } } diff --git a/Fauna/Exceptions/AbortException.cs b/Fauna/Exceptions/AbortException.cs index 71fd4020..2b340b60 100644 --- a/Fauna/Exceptions/AbortException.cs +++ b/Fauna/Exceptions/AbortException.cs @@ -8,48 +8,37 @@ namespace Fauna.Exceptions; /// public class AbortException : QueryRuntimeException { - private readonly SerializationContext serializationCtx; - private readonly Dictionary cache = new(); + private readonly SerializationContext _serializationCtx; + private readonly Dictionary _cache = new(); private static readonly Type NonTypedKey = typeof(object); /// /// Initializes a new instance of the class with a specified error message and query failure details. /// + /// The /// The object containing details about the query failure. /// The error message that explains the reason for the exception. public AbortException(SerializationContext ctx, QueryFailure queryFailure, string message) : base(queryFailure, message) { - this.serializationCtx = ctx; + _serializationCtx = ctx; } - - /// - /// Initializes a new instance of the class with a specified error message, a reference to the inner exception, and query failure details. - /// - /// The object containing details about the query failure. - /// The error message that explains the reason for the exception. - /// The exception that is the cause of the current exception, or a null reference if no inner exception is specified. - public AbortException(SerializationContext ctx, QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) - { - this.serializationCtx = ctx; - } - + /// /// Retrieves the deserialized data associated with the abort operation as an object. /// /// The deserialized data as an object, or null if no data is available. public object? GetData() { - if (!cache.TryGetValue(NonTypedKey, out var cachedData)) + if (!_cache.TryGetValue(NonTypedKey, out var cachedData)) { var abortDataString = QueryFailure.ErrorInfo.Abort?.ToString(); if (!string.IsNullOrEmpty(abortDataString)) { var reader = new Utf8FaunaReader(abortDataString); reader.Read(); - cachedData = Serializer.Deserialize(serializationCtx, ref reader); - cache[NonTypedKey] = cachedData; + cachedData = Serializer.Deserialize(_serializationCtx, ref reader); + _cache[NonTypedKey] = cachedData; } } return cachedData; @@ -63,15 +52,15 @@ public AbortException(SerializationContext ctx, QueryFailure queryFailure, strin public T? GetData() { var typeKey = typeof(T); - if (!cache.TryGetValue(typeKey, out var cachedData)) + if (!_cache.TryGetValue(typeKey, out var cachedData)) { var abortDataString = QueryFailure.ErrorInfo.Abort.ToString(); if (!string.IsNullOrEmpty(abortDataString)) { var reader = new Utf8FaunaReader(abortDataString); reader.Read(); - T? deserializedResult = Serializer.Deserialize(serializationCtx, ref reader); - cache[typeKey] = deserializedResult; + T? deserializedResult = Serializer.Deserialize(_serializationCtx, ref reader); + _cache[typeKey] = deserializedResult; return deserializedResult; } } diff --git a/Fauna/Exceptions/AuthenticationException.cs b/Fauna/Exceptions/AuthenticationException.cs index 023d6e7b..bfe2e50e 100644 --- a/Fauna/Exceptions/AuthenticationException.cs +++ b/Fauna/Exceptions/AuthenticationException.cs @@ -4,7 +4,4 @@ public class AuthenticationException : ServiceException { public AuthenticationException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public AuthenticationException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } -} \ No newline at end of file +} diff --git a/Fauna/Exceptions/AuthorizationException.cs b/Fauna/Exceptions/AuthorizationException.cs index 03303748..f4a1521c 100644 --- a/Fauna/Exceptions/AuthorizationException.cs +++ b/Fauna/Exceptions/AuthorizationException.cs @@ -4,7 +4,4 @@ public class AuthorizationException : ServiceException { public AuthorizationException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public AuthorizationException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } -} \ No newline at end of file +} diff --git a/Fauna/Exceptions/ContendedTransactionException.cs b/Fauna/Exceptions/ContendedTransactionException.cs index 94ca1534..c40d743f 100644 --- a/Fauna/Exceptions/ContendedTransactionException.cs +++ b/Fauna/Exceptions/ContendedTransactionException.cs @@ -8,7 +8,4 @@ public class ContendedTransactionException : ServiceException, IRetryableExcepti { public ContendedTransactionException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public ContendedTransactionException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/InvalidRequestException.cs b/Fauna/Exceptions/InvalidRequestException.cs index 2d50d051..04797cb0 100644 --- a/Fauna/Exceptions/InvalidRequestException.cs +++ b/Fauna/Exceptions/InvalidRequestException.cs @@ -7,7 +7,4 @@ public class InvalidRequestException : ServiceException { public InvalidRequestException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public InvalidRequestException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/QueryCheckException.cs b/Fauna/Exceptions/QueryCheckException.cs index 7ed9c40c..f36da0ad 100644 --- a/Fauna/Exceptions/QueryCheckException.cs +++ b/Fauna/Exceptions/QueryCheckException.cs @@ -4,7 +4,4 @@ public class QueryCheckException : ServiceException { public QueryCheckException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public QueryCheckException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/QueryRuntimeException.cs b/Fauna/Exceptions/QueryRuntimeException.cs index 4feb006c..8b1b1f3c 100644 --- a/Fauna/Exceptions/QueryRuntimeException.cs +++ b/Fauna/Exceptions/QueryRuntimeException.cs @@ -7,7 +7,4 @@ public class QueryRuntimeException : ServiceException { public QueryRuntimeException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public QueryRuntimeException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/QueryTimeoutException.cs b/Fauna/Exceptions/QueryTimeoutException.cs index ad0d95e0..5727cc6d 100644 --- a/Fauna/Exceptions/QueryTimeoutException.cs +++ b/Fauna/Exceptions/QueryTimeoutException.cs @@ -4,7 +4,4 @@ public class QueryTimeoutException : ServiceException { public QueryTimeoutException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public QueryTimeoutException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/ServiceException.cs b/Fauna/Exceptions/ServiceException.cs index 5c5bb078..3aad495a 100644 --- a/Fauna/Exceptions/ServiceException.cs +++ b/Fauna/Exceptions/ServiceException.cs @@ -18,13 +18,4 @@ public class ServiceException : FaunaException /// The error message that explains the reason for the exception. public ServiceException(QueryFailure queryFailure, string message) : base(message) => QueryFailure = queryFailure; - - /// - /// Initializes a new instance of the class with a specified query failure details, error message, and a reference to the inner exception. - /// - /// The object containing details about the query failure. - /// The error message that explains the reason for the exception. - /// The exception that is the cause of the current exception, represented by an object. - public ServiceException(QueryFailure queryFailure, string message, Exception innerException) - : base(message, innerException) => QueryFailure = queryFailure; } diff --git a/Fauna/Exceptions/ThrottlingException.cs b/Fauna/Exceptions/ThrottlingException.cs index fca6584c..ecea9251 100644 --- a/Fauna/Exceptions/ThrottlingException.cs +++ b/Fauna/Exceptions/ThrottlingException.cs @@ -8,7 +8,4 @@ public class ThrottlingException : ServiceException, IRetryableException { public ThrottlingException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public ThrottlingException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } } diff --git a/Fauna/Exceptions/WriteConstraintException.cs b/Fauna/Exceptions/WriteConstraintException.cs index fdbc9d9d..c32e5d89 100644 --- a/Fauna/Exceptions/WriteConstraintException.cs +++ b/Fauna/Exceptions/WriteConstraintException.cs @@ -4,7 +4,4 @@ public class WriteConstraintException : QueryRuntimeException { public WriteConstraintException(QueryFailure queryFailure, string message) : base(queryFailure, message) { } - - public WriteConstraintException(QueryFailure queryFailure, string message, Exception innerException) - : base(queryFailure, message, innerException) { } }