From cba16e1537e69a6c5a6f319124bea0ffd3b849f0 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Fri, 18 Oct 2019 07:32:39 -0700 Subject: [PATCH 1/7] DocumentClientException to ResponseMessage now uses ToString() to preserve the stack trace and other information. --- Microsoft.Azure.Cosmos/src/Util/Extensions.cs | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs index 983e970f48..76b3d0575e 100644 --- a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs +++ b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs @@ -16,8 +16,6 @@ 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)); @@ -59,24 +57,7 @@ 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); - string reasonPhraseString = string.Empty; - if (!string.IsNullOrEmpty(dce.Message)) - { - if (dce.Message.IndexOfAny(Extensions.NewLineCharacters) >= 0) - { - StringBuilder sb = new StringBuilder(dce.Message); - sb = sb.Replace("\r", string.Empty); - sb = sb.Replace("\n", string.Empty); - reasonPhraseString = sb.ToString(); - } - else - { - reasonPhraseString = dce.Message; - } - } - - cosmosResponse.ErrorMessage = reasonPhraseString; - cosmosResponse.Error = dce.Error; + cosmosResponse.ErrorMessage = dce.ToString(); if (dce.Headers != null) { From 0c9a3d2db8f721eb34c957bb8d55d281755388a6 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Mon, 21 Oct 2019 10:14:38 -0700 Subject: [PATCH 2/7] Adding unit test --- .../CosmosExceptionTests.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosExceptionTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosExceptionTests.cs index 874be09dc4..7b0b58af51 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosExceptionTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/CosmosExceptionTests.cs @@ -86,5 +86,30 @@ public void EnsureSuccessStatusCode_ThrowsOnFailure_ContainsJsonBody() } } } + + [TestMethod] + public void VerifyDocumentClientExceptionToResponseMessage() + { + string errorMessage = "Test Exception!"; + DocumentClientException dce = null; + try + { + throw new DocumentClientException( + message: errorMessage, + statusCode: HttpStatusCode.BadRequest, + subStatusCode: SubStatusCodes.WriteForbidden); + } + catch (DocumentClientException exception) + { + dce = exception; + } + + ResponseMessage responseMessage = dce.ToCosmosResponseMessage(null); + Assert.IsFalse(responseMessage.IsSuccessStatusCode); + Assert.AreEqual(HttpStatusCode.BadRequest, responseMessage.StatusCode); + Assert.AreEqual(SubStatusCodes.WriteForbidden, responseMessage.Headers.SubStatusCode); + Assert.IsTrue(responseMessage.ErrorMessage.Contains(errorMessage)); + Assert.IsTrue(responseMessage.ErrorMessage.Contains("VerifyDocumentClientExceptionToResponseMessage"), $"Message should have method name for the stack trace {responseMessage.ErrorMessage}"); + } } } From 7cca31b559992725e8a09ee8ba5b3b609fd397c4 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Mon, 21 Oct 2019 10:21:49 -0700 Subject: [PATCH 3/7] Updated changelog --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index cc85828149..42ab092f65 100644 --- a/changelog.md +++ b/changelog.md @@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [#905](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/909) Fixed linq camel case bug - +- [#921](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/921) Fixed error handling to preserve stack trace in certain scenarios ## [3.3.1](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.3.1) - 2019-10-11 From ac9231e25ace9d699cf1cddf95e10515d60652e6 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Tue, 22 Oct 2019 04:43:20 -0700 Subject: [PATCH 4/7] Updated test --- .../tests/Microsoft.Azure.Cosmos.Tests/HandlerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HandlerTests.cs b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HandlerTests.cs index 545990a21d..d385aee28f 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HandlerTests.cs +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.Tests/HandlerTests.cs @@ -307,7 +307,7 @@ public void TestAggregateExceptionConverter() ResponseMessage response = TransportHandler.AggregateExceptionConverter(ae, null); Assert.IsNotNull(response); Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode); - Assert.IsTrue(response.ErrorMessage.StartsWith(errorMessage)); + Assert.IsTrue(response.ErrorMessage.Contains(errorMessage)); } private class SomePayload From 87f86631a4792b5b0b81fbdb107cc682992c3679 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Wed, 23 Oct 2019 06:48:45 -0700 Subject: [PATCH 5/7] Updated linq expected error message --- .../LinqGeneralBaselineTests.TestThenByTranslation.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml index aa7e2abb6d..839d3ef6ca 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestThenByTranslation.xml @@ -123,7 +123,7 @@ ORDER BY v0 DESC, v1 ASC SELECT VALUE root FROM root ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC ]]> - + @@ -136,7 +136,7 @@ ORDER BY root["FamilyId"] ASC, root["FamilyId"] ASC ]]> SELECT VALUE root FROM root ORDER BY root["FamilyId"] ASC, root["FamilyId"] DESC ]]> - + @@ -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 ]]> - + From 8b73c8ef118c6ff059fc655759b506540394d284 Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Wed, 23 Oct 2019 07:45:05 -0700 Subject: [PATCH 6/7] Fixed another linq test --- ...lBaselineTests.TestDistinctTranslation.xml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestDistinctTranslation.xml b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestDistinctTranslation.xml index f0b0377995..8d1906cf11 100644 --- a/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestDistinctTranslation.xml +++ b/Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/BaselineTest/TestBaseline/LinqGeneralBaselineTests.TestDistinctTranslation.xml @@ -414,7 +414,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -434,7 +434,7 @@ JOIN ( WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20)) ORDER BY v2 ASC ]]> - + @@ -454,7 +454,7 @@ JOIN ( WHERE ((LENGTH(v2["FamilyName"]) > 10) AND (LENGTH(v2["FamilyName"]) < 20)) ORDER BY v2 ASC ]]> - + @@ -497,7 +497,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -580,7 +580,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -600,7 +600,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -620,7 +620,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2["GivenName"]["Length"] ASC ]]> - + @@ -640,7 +640,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2["GivenName"]["Length"] ASC ]]> - + @@ -660,7 +660,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -680,7 +680,7 @@ JOIN ( WHERE (LENGTH(v2["FamilyName"]) > 10) ORDER BY v2 ASC ]]> - + @@ -717,7 +717,7 @@ JOIN ( ) AS v2 ORDER BY v2["FamilyName"] ASC ]]> - + @@ -736,7 +736,7 @@ JOIN ( ) AS v2 ORDER BY v2["FamilyName"] ASC ]]> - + @@ -806,7 +806,7 @@ JOIN ( ) AS v1 ORDER BY v1 ASC ]]> - + @@ -826,7 +826,7 @@ JOIN ( WHERE (LENGTH(v1) > 10) ORDER BY v1 ASC ]]> - + From c94035834531ba9e4bb1f7b3797664e0155cf2ab Mon Sep 17 00:00:00 2001 From: Jake Willey Date: Wed, 20 Nov 2019 07:30:58 -0800 Subject: [PATCH 7/7] Fixed bad merge --- Microsoft.Azure.Cosmos/src/Util/Extensions.cs | 2 +- changelog.md | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs index ff628c3a1f..467e39b56e 100644 --- a/Microsoft.Azure.Cosmos/src/Util/Extensions.cs +++ b/Microsoft.Azure.Cosmos/src/Util/Extensions.cs @@ -18,7 +18,7 @@ internal static class Extensions { private static readonly char[] NewLineCharacters = new[] { '\r', '\n' }; - internal static ResponseMessage ToCosmosResponseMessage(this DocumentServiceResponse response, RequestMessage requestMessage) + internal static ResponseMessage ToCosmosResponseMessage(this DocumentServiceResponse documentServiceResponse, RequestMessage requestMessage) { Debug.Assert(requestMessage != null, nameof(requestMessage)); diff --git a/changelog.md b/changelog.md index 0abdd08f8b..eace8b66fd 100644 --- a/changelog.md +++ b/changelog.md @@ -13,7 +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 +- [#921](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/921) Fixed error handling to preserve stack trace in certain scenarios - [#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. @@ -40,14 +40,12 @@ 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 +- [#936](https://github.com/Azure/azure-cosmos-dotnet-v3/pull/936) Fixed bulk requests with large resources to have natural exception ## [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. - ## [3.3.2](https://www.nuget.org/packages/Microsoft.Azure.Cosmos/3.3.2) - 2019-10-16