Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CosmosNullReferenceException: Refactors CosmosNullReferenceException to pass along InnerException property on parent NullReferenceException #3713

Merged
merged 5 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Microsoft.Azure.Cosmos/src/Resource/ClientContextCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ private async Task<TResult> RunWithDiagnosticsHelperAsync<TResult>(
catch (NullReferenceException nullRefException) when (!(nullRefException is CosmosNullReferenceException))
{
CosmosNullReferenceException nullException = new CosmosNullReferenceException(
nullRefException.Message,
jeet1995 marked this conversation as resolved.
Show resolved Hide resolved
nullRefException,
trace);
recorder.MarkFailed(nullException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ internal class CosmosNullReferenceException : NullReferenceException
/// Create an instance of CosmosNullReferenceException
/// </summary>
internal CosmosNullReferenceException(
String message,
jeet1995 marked this conversation as resolved.
Show resolved Hide resolved
NullReferenceException originalException,
ITrace trace)
ITrace trace)
: base(message ?? throw new ArgumentNullException(nameof(message)), originalException ?? throw new ArgumentNullException(nameof(originalException)))
jeet1995 marked this conversation as resolved.
Show resolved Hide resolved
{
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 @@ -33,13 +33,15 @@ public void CosmosNullRefWrapingTest()
using (trace.StartChild("startChild")) { }

CosmosNullReferenceException cosmosNullReferenceException = new CosmosNullReferenceException(
nullReferenceException.Message,
nullReferenceException,
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 +50,14 @@ public void CosmosNullRefWrapingTest()
Assert.IsTrue(cosmosToString.Contains(message));
Assert.IsTrue(cosmosToString.Contains(rootTraceName));
}

[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
[DataRow(null, null)]
[DataRow("", null)]
public void ExpectArgumentNullExceptionTest(String message, NullReferenceException nullReferenceException)
{
_ = new CosmosNullReferenceException(message, nullReferenceException, NoOpTrace.Singleton);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void MarkFailedTest()

Assert.IsTrue(OpenTelemetryCoreRecorder.IsExceptionRegistered(
new CosmosNullReferenceException(
"",
new NullReferenceException(),
NoOpTrace.Singleton),
default));
Expand Down