Skip to content

Commit

Permalink
CosmosNullReferenceException: Refactors CosmosNullReferenceException …
Browse files Browse the repository at this point in the history
…to pass along InnerException property on parent NullReferenceException (#3713) (#3760)

* Passed inner exception details to NullReferenceException ctor when instantiating CosmosNullReferenceException.

* Added unit tests.

* Addressed PR feedback.

Co-authored-by: Abhijeet Mohanty <[email protected]>
  • Loading branch information
ealsur and jeet1995 authored Mar 13, 2023
1 parent 5ed6c8e commit 176f916
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ internal class CosmosNullReferenceException : NullReferenceException
/// </summary>
internal CosmosNullReferenceException(
NullReferenceException originalException,
ITrace trace)
ITrace trace)
: base(originalException?.Message ?? throw new ArgumentNullException(nameof(originalException)), originalException ?? throw new ArgumentNullException(nameof(originalException)))
{
this.originalException = originalException ?? throw new ArgumentNullException(nameof(originalException));
this.originalException = originalException;

if (trace == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ public void CosmosNullRefWrapingTest()
trace);

Assert.AreEqual(nullReferenceException.StackTrace, cosmosNullReferenceException.StackTrace);
Assert.AreEqual(nullReferenceException.InnerException, cosmosNullReferenceException.InnerException);
Assert.AreEqual(nullReferenceException, cosmosNullReferenceException.InnerException);
Assert.AreEqual(nullReferenceException.Data, cosmosNullReferenceException.Data);


Assert.IsTrue(cosmosNullReferenceException.Message.Contains(message));
Assert.IsTrue(cosmosNullReferenceException.Message.Contains(rootTraceName));
Assert.AreNotEqual(nullReferenceException.Message, cosmosNullReferenceException.Message);
Expand All @@ -48,5 +49,12 @@ public void CosmosNullRefWrapingTest()
Assert.IsTrue(cosmosToString.Contains(message));
Assert.IsTrue(cosmosToString.Contains(rootTraceName));
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ExpectArgumentNullExceptionTest()
{
_ = new CosmosNullReferenceException(null, NoOpTrace.Singleton);
}
}
}

0 comments on commit 176f916

Please sign in to comment.