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

CosmosOperationCanceledException: Adds short link and cancellation token status into message #3234

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos
{
using System;
using System.Collections;
using System.Threading;
using Microsoft.Azure.Cosmos.Diagnostics;
using Microsoft.Azure.Cosmos.Tracing;

Expand All @@ -31,7 +32,7 @@ public CosmosOperationCanceledException(
{
this.originalException = originalException ?? throw new ArgumentNullException(nameof(originalException));
this.Diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics));
this.lazyMessage = this.CreateLazyMessage();
this.lazyMessage = this.CreateLazyMessage(originalException.CancellationToken);
}

internal CosmosOperationCanceledException(
Expand All @@ -47,7 +48,7 @@ internal CosmosOperationCanceledException(

trace.AddDatum("Operation Cancelled Exception", originalException);
this.Diagnostics = new CosmosTraceDiagnostics(trace);
this.lazyMessage = this.CreateLazyMessage();
this.lazyMessage = this.CreateLazyMessage(originalException.CancellationToken);
}

/// <inheritdoc/>
Expand Down Expand Up @@ -90,9 +91,9 @@ public override string ToString()
return $"{this.originalException} {Environment.NewLine}CosmosDiagnostics: {this.Diagnostics}";
imanvt marked this conversation as resolved.
Show resolved Hide resolved
}

private Lazy<string> CreateLazyMessage()
private Lazy<string> CreateLazyMessage(CancellationToken token)
{
return new Lazy<string>(() => $"{this.originalException.Message} {Environment.NewLine}CosmosDiagnostics: {this.Diagnostics}");
return new Lazy<string>(() => $"{this.originalException.Message} {Environment.NewLine}CosmosDiagnostics: {this.Diagnostics} {Environment.NewLine}Learn more at: https://aka.ms/cosmosdb-tsg-request-timeout {Environment.NewLine}Cancellation Token has expired: {token.IsCancellationRequested}");
imanvt marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ StoreResponse sendDirectFunc(Uri uri, ResourceOperation resourceOperation, Docum

((MockDocumentClient)client.DocumentClient).MockGlobalEndpointManager.Verify(gep => gep.MarkEndpointUnavailableForRead(It.IsAny<Uri>()), Times.Once, "Should had marked the endpoint unavailable");
((MockDocumentClient)client.DocumentClient).MockGlobalEndpointManager.Verify(gep => gep.RefreshLocationAsync(false), Times.Once, "Should had refreshed the account information");

string expectedHelpLink = "https://aka.ms/cosmosdb-tsg-request-timeout";
string expectedCancellationTokenStatus = $"Cancellation Token has expired: {cancellationToken.IsCancellationRequested}";
Assert.IsTrue(ex.Message.Contains(expectedHelpLink));
Assert.IsTrue(ex.Message.Contains(expectedCancellationTokenStatus));
}
}

Expand Down