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

Updated exception messages #1298

Merged
merged 9 commits into from
Mar 25, 2020
Merged

Updated exception messages #1298

merged 9 commits into from
Mar 25, 2020

Conversation

j82w
Copy link
Contributor

@j82w j82w commented Mar 23, 2020

Pull Request Template

Description

Updating the exception messages to provide a consistent story with all the information. This ensures that if a user only collects a Message or other property there will always be the information required to troubleshoot it.

ResponseMessage

  1. ResponseMessage.Content will always be null for exception scenarios
  2. ResponseMessage.ErrorMessage will contain the same thing as CosmosException.Message (no stack trace, no diagnostics)

CosmosException:

  1. CosmosException.Message, ResponseMessage.ErrorMessage contain the same value.
  2. CosmosException.ToString() includes stacktrace, diagnostics, error message, and all relevant information.
  3. CosmosException.ResponseBody is the raw response from the service or DCE.Message
{
  "Errors": [
    "One of the specified pre-condition is not met"
  ]
}

Example output CosmosException.Message and ResponseMessage.ErrorMessage

Response status code does not indicate success: PreconditionFailed (412); Substatus: 0; ActivityId: 9257c3ae-15fc-4c9f-a6c8-d995107c16df; Reason: ({
  "Errors": [
    "One of the specified pre-condition is not met"
  ]
});

Example output CosmosException.ToString()

Microsoft.Azure.Cosmos.CosmosException : Response status code does not indicate success: PreconditionFailed (412); Substatus: 0; ActivityId: 9257c3ae-15fc-4c9f-a6c8-d995107c16df; Reason: ({
  "Errors": [
    "One of the specified pre-condition is not met"
  ]
});
   at Microsoft.Azure.Cosmos.ResponseMessage.EnsureSuccessStatusCode() in C:\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Handler\ResponseMessage.cs:line 153
   at Microsoft.Azure.Cosmos.CosmosResponseFactory.ProcessMessageAsync[T](Task`1 cosmosResponseTask, Func`2 createResponse) in C:\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Resource\CosmosResponseFactory.cs:line 256
   at Microsoft.Azure.Cosmos.ContainerCore.UpsertItemAsync[T](T item, Nullable`1 partitionKey, ItemRequestOptions requestOptions, CancellationToken cancellationToken) in C:\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\src\Resource\Container\ContainerCore.Items.cs:line 173
   at Microsoft.Azure.Cosmos.SDK.EmulatorTests.CosmosItemTests.ItemRequestOptionAccessConditionTest() in C:\azure-cosmos-dotnet-v3\Microsoft.Azure.Cosmos\tests\Microsoft.Azure.Cosmos.EmulatorTests\CosmosItemTests.cs:line 1249
{"Summary":{"StartUtc":"2020-03-25T19:59:26.9650800Z","TotalElapsedTime":"00:00:00.1440249","UserAgent":"cosmos-netstandard-sdk/3.7.0|3.7.1|96609|X64|Microsoft Windows 10.0.18363 |.NET Core 4.6.28325.01|","TotalRequestCount":1,"FailedRequestCount":1},"Context":[{"Id":"ItemSerialize","ElapsedTime":"00:00:00.0000571"},{"Id":"ExtractPkValue","ElapsedTime":"00:00:00.0001130"},{"Id":"AggregatedClientSideRequestStatistics","ContactedReplicas":[{"Count":12,"Uri":"rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer4/partitions/a4cb4950-38c8-11e6-8106-8cdcd42c33be/replicas/1p/"}],"RegionsContacted":["https://127.0.0.1:8081/"],"FailedReplicas":[]},{"Id":"Microsoft.Azure.Cosmos.Handlers.RetryHandler","ElapsedTime":"00:00:00.0067842"},{"Id":"Microsoft.Azure.Cosmos.Handlers.RouterHandler","ElapsedTime":"00:00:00.0034801"},{"Id":"TransportHandler","ElapsedTime":"00:00:00.0034742"},{"Id":"StoreResponseStatistics","ResponseTimeUtc":"2020-03-25T19:59:26.9678463Z","ResourceType":"Document","OperationType":"Upsert","LocationEndpoint":"https://127.0.0.1:8081/","StoreResult":"StorePhysicalAddress: rntbd://127.0.0.1:10253/apps/DocDbApp/services/DocDbServer4/partitions/a4cb4950-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, LSN: 130, GlobalCommittedLsn: -1, PartitionKeyRangeId: 0, IsValid: True, StatusCode: 412, SubStatusCode: 0, RequestCharge: 1.24, ItemLSN: -1, SessionToken: -1#130, UsingLocalLSN: False, TransportException: null"}]}

@j82w j82w self-assigned this Mar 23, 2020
@kirankumarkolli
Copy link
Member

Ideally have full context on all surfaces unless its an issue.

Copy link
Member

@FabianMeiswinkel FabianMeiswinkel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Debug.Assert instead for internal members?

@@ -68,6 +69,9 @@ public class CosmosException : Exception
this.DiagnosticsContext = new CosmosDiagnosticsContextCore();
}

/// <inheritdoc/>
public override string Message => this.ToString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove - ToString() contain information like the call stack that is intentionally not included in the Exception.Message. Changing this violates basic Exception contract - same message as ToString without callstack or diagnostics might be fine or the base class implementation just using the message explicitly passed in. I think we discussed this in the past - and due to the fact that the ctor of CosmosException is internal - so the exception cannot ever be created by customers this is kind of a gray area - you could argue that we are the only entity deciding which information is critical. But if there is no hard reason requiring us to include stacktrace and diagnostics I wouldn't include them in Message to avoid exposing PII or data considered sensitive by customers in an Exception.Message - where they usually aren't included.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind - I remember teh discussion and think the stackTrace and diagnostics would be null in the exceptions actually thornw to the customer - and were just used to pass through context through the request pipeline. If so ignore the comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated it so the Message only contains the StatusCode, SubStatusCode, ActivityId, and original message from the service. Only the ToString() will contain the full stack trace and diagnostics.

@j82w j82w merged commit dc77b03 into master Mar 25, 2020
@j82w j82w deleted the users/jawilley/bug/exceptionMessage branch March 25, 2020 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants