Skip to content

Commit

Permalink
Remove inner exceptions where not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwpedro committed Jan 4, 2024
1 parent 31f9f15 commit fb70fbb
Show file tree
Hide file tree
Showing 22 changed files with 13 additions and 195 deletions.
5 changes: 0 additions & 5 deletions Fauna.Test/Exceptions/AbortException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/AuthenticationException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/AuthorizationException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/ContendedTransactionException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/InvalidRequestException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/QueryCheckException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/QueryRuntimeException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/QueryTimeoutException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/ServiceException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/ThrottlingException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
13 changes: 0 additions & 13 deletions Fauna.Test/Exceptions/WriteConstraintException.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
33 changes: 11 additions & 22 deletions Fauna/Exceptions/AbortException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,37 @@ namespace Fauna.Exceptions;
/// </summary>
public class AbortException : QueryRuntimeException
{
private readonly SerializationContext serializationCtx;
private readonly Dictionary<Type, object?> cache = new();
private readonly SerializationContext _serializationCtx;
private readonly Dictionary<Type, object?> _cache = new();
private static readonly Type NonTypedKey = typeof(object);

/// <summary>
/// Initializes a new instance of the <see cref="AbortException"/> class with a specified error message and query failure details.
/// </summary>
/// <param name="ctx">The <see cref="SerializationContext"/></param>
/// <param name="queryFailure">The <see cref="QueryFailure"/> object containing details about the query failure.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
public AbortException(SerializationContext ctx, QueryFailure queryFailure, string message)
: base(queryFailure, message)
{
this.serializationCtx = ctx;
_serializationCtx = ctx;
}

/// <summary>
/// Initializes a new instance of the <see cref="AbortException"/> class with a specified error message, a reference to the inner exception, and query failure details.
/// </summary>
/// <param name="queryFailure">The <see cref="QueryFailure"/> object containing details about the query failure.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, or a null reference if no inner exception is specified.</param>
public AbortException(SerializationContext ctx, QueryFailure queryFailure, string message, Exception innerException)
: base(queryFailure, message, innerException)
{
this.serializationCtx = ctx;
}


/// <summary>
/// Retrieves the deserialized data associated with the abort operation as an object.
/// </summary>
/// <returns>The deserialized data as an object, or null if no data is available.</returns>
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;
Expand All @@ -63,15 +52,15 @@ public AbortException(SerializationContext ctx, QueryFailure queryFailure, strin
public T? GetData<T>()
{
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<T>(serializationCtx, ref reader);
cache[typeKey] = deserializedResult;
T? deserializedResult = Serializer.Deserialize<T>(_serializationCtx, ref reader);
_cache[typeKey] = deserializedResult;
return deserializedResult;
}
}
Expand Down
5 changes: 1 addition & 4 deletions Fauna/Exceptions/AuthenticationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
}
5 changes: 1 addition & 4 deletions Fauna/Exceptions/AuthorizationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/ContendedTransactionException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/InvalidRequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/QueryCheckException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/QueryRuntimeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/QueryTimeoutException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
9 changes: 0 additions & 9 deletions Fauna/Exceptions/ServiceException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,4 @@ public class ServiceException : FaunaException
/// <param name="message">The error message that explains the reason for the exception.</param>
public ServiceException(QueryFailure queryFailure, string message)
: base(message) => QueryFailure = queryFailure;

/// <summary>
/// Initializes a new instance of the <see cref="ServiceException"/> class with a specified query failure details, error message, and a reference to the inner exception.
/// </summary>
/// <param name="queryFailure">The <see cref="QueryFailure"/> object containing details about the query failure.</param>
/// <param name="message">The error message that explains the reason for the exception.</param>
/// <param name="innerException">The exception that is the cause of the current exception, represented by an <see cref="Exception"/> object.</param>
public ServiceException(QueryFailure queryFailure, string message, Exception innerException)
: base(message, innerException) => QueryFailure = queryFailure;
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/ThrottlingException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}
3 changes: 0 additions & 3 deletions Fauna/Exceptions/WriteConstraintException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
}

0 comments on commit fb70fbb

Please sign in to comment.