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

Preserve stack trace DocumentClientException to ResponseMessage #921

Merged
merged 10 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Merge to latest
  • Loading branch information
Jake Willey committed Nov 20, 2019
commit ec0bb4515e500be7fcd2fb263291ca9f47d9172e
19 changes: 17 additions & 2 deletions Microsoft.Azure.Cosmos/src/Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace Microsoft.Azure.Cosmos

internal static class Extensions
{
private static readonly char[] NewLineCharacters = new[] { '\r', '\n' };

internal static ResponseMessage ToCosmosResponseMessage(this DocumentServiceResponse response, RequestMessage requestMessage)
{
Debug.Assert(requestMessage != null, nameof(requestMessage));
Expand Down Expand Up @@ -59,8 +61,21 @@ internal static ResponseMessage ToCosmosResponseMessage(this DocumentClientExcep
}

// if there is a status code then it came from the backend, return error as http error instead of throwing the exception
ResponseMessage cosmosResponse = new ResponseMessage(dce.StatusCode ?? HttpStatusCode.InternalServerError, request);
cosmosResponse.ErrorMessage = dce.ToString();
ResponseMessage responseMessage = new ResponseMessage(documentClientException.StatusCode ?? HttpStatusCode.InternalServerError, requestMessage);
string reasonPhraseString = documentClientException.ToString();
if (!string.IsNullOrEmpty(reasonPhraseString))
{
if (documentClientException.Message.IndexOfAny(Extensions.NewLineCharacters) >= 0)
{
StringBuilder sb = new StringBuilder(reasonPhraseString);
sb = sb.Replace("\r", string.Empty);
sb = sb.Replace("\n", string.Empty);
reasonPhraseString = sb.ToString();
}
}

responseMessage.ErrorMessage = reasonPhraseString;
responseMessage.Error = documentClientException.Error;

if (documentClientException.Headers != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -434,7 +434,7 @@ JOIN (
WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20))
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -454,7 +454,7 @@ JOIN (
WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20))
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -497,7 +497,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -580,7 +580,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -600,7 +600,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -620,7 +620,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2["GivenName"]["Length"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -640,7 +640,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2["GivenName"]["Length"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -660,7 +660,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -680,7 +680,7 @@ JOIN (
WHERE (LENGTH(v2["FamilyName"]) > 10)
ORDER BY v2 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -717,7 +717,7 @@ JOIN (
) AS v2
ORDER BY v2["FamilyName"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -736,7 +736,7 @@ JOIN (
) AS v2
ORDER BY v2["FamilyName"] ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -806,7 +806,7 @@ JOIN (
) AS v1
ORDER BY v1 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -826,7 +826,7 @@ JOIN (
WHERE (LENGTH(v1) > 10)
ORDER BY v1 ASC
]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ ORDER BY v0 DESC, v1 ASC
SELECT VALUE root
FROM root
ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC ]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["The order by query does not have a corresponding composite index that it can be served from."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand All @@ -136,7 +136,7 @@ ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC ]]></SqlQuery>
SELECT VALUE root
FROM root
ORDER BY root["FamilyId"] ASC, root["FamilyId"] DESC ]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["The order by query does not have a corresponding composite index that it can be served from."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down Expand Up @@ -633,7 +633,7 @@ FROM root
JOIN f0 IN root["Records"]["Transactions"]
WHERE (ARRAY_LENGTH(root["Children"]) > 0)
ORDER BY f0["Type"] ASC, f0["Amount"] ASC ]]></SqlQuery>
<ErrorMessage><![CDATA[Response status code does not indicate success: 400 Substatus: 0 Reason: (Microsoft.Azure.Documents.DocumentClientException: Message: {"Errors":["Order-by over correlated collections is not supported."]}]]></ErrorMessage>
<ErrorMessage><![CDATA[Status Code: BadRequest]]></ErrorMessage>
</Output>
</Result>
<Result>
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- [#936](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/936) Fixed bulk requests with large resources to have natural exception
- [#944](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/944) Change Feed Processor won't use user serializer for internal operations
- [#988](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/988) Fixed query mutating due to retry of gone / name cache is stale.
- [#999](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/999) Fixed grabbing extra page and updated continuation token on exception path.
Expand All @@ -39,6 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- [#901](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/901) Fixed a bug causing query response to create a new stream for each content call
- [#918](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/918) Fixed serializer being used for Scripts, Permissions, and Conflict related iterators

## <a name="3.3.3"/> [3.3.3](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.3.3) - 2019-10-30

- [#837](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/837) Fixed group by bug for non-Windows platforms
- [#921](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/921) Fixed error handling to preserve stack trace in certain scenarios
- [#927](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/927) Fixed query returning partial results instead of error
flow.
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.