Skip to content

Commit 38d1bcc

Browse files
authored
CosmosNullReferenceException: Refactors CosmosNullReferenceException to pass along InnerException property on parent NullReferenceException (#3713)
* Passed inner exception details to NullReferenceException ctor when instantiating CosmosNullReferenceException. * Added unit tests. * Addressed PR feedback.
1 parent 4e923da commit 38d1bcc

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Microsoft.Azure.Cosmos/src/Resource/CosmosExceptions/CosmosNullReferenceException.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ internal class CosmosNullReferenceException : NullReferenceException
2525
/// </summary>
2626
internal CosmosNullReferenceException(
2727
NullReferenceException originalException,
28-
ITrace trace)
28+
ITrace trace)
29+
: base(originalException?.Message ?? throw new ArgumentNullException(nameof(originalException)), originalException ?? throw new ArgumentNullException(nameof(originalException)))
2930
{
30-
this.originalException = originalException ?? throw new ArgumentNullException(nameof(originalException));
31+
this.originalException = originalException;
3132

3233
if (trace == null)
3334
{

Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosNullReferenceExceptionTests.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public void CosmosNullRefWrapingTest()
3737
trace);
3838

3939
Assert.AreEqual(nullReferenceException.StackTrace, cosmosNullReferenceException.StackTrace);
40-
Assert.AreEqual(nullReferenceException.InnerException, cosmosNullReferenceException.InnerException);
40+
Assert.AreEqual(nullReferenceException, cosmosNullReferenceException.InnerException);
4141
Assert.AreEqual(nullReferenceException.Data, cosmosNullReferenceException.Data);
4242

43+
4344
Assert.IsTrue(cosmosNullReferenceException.Message.Contains(message));
4445
Assert.IsTrue(cosmosNullReferenceException.Message.Contains(rootTraceName));
4546
Assert.AreNotEqual(nullReferenceException.Message, cosmosNullReferenceException.Message);
@@ -48,5 +49,12 @@ public void CosmosNullRefWrapingTest()
4849
Assert.IsTrue(cosmosToString.Contains(message));
4950
Assert.IsTrue(cosmosToString.Contains(rootTraceName));
5051
}
52+
53+
[TestMethod]
54+
[ExpectedException(typeof(ArgumentNullException))]
55+
public void ExpectArgumentNullExceptionTest()
56+
{
57+
_ = new CosmosNullReferenceException(null, NoOpTrace.Singleton);
58+
}
5159
}
5260
}

0 commit comments

Comments
 (0)