question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CosmosException.ResponseBody doesn't actually contain the response body

See original GitHub issue

Describe the bug CosmosException.ResponseBody contains the details of an .NET exception, even though the name clearly implies that it should be, well, the response body… Cosmos DB error responses are already a mess; why does the SDK have to make things even worse? The interesting part (i.e. the JSON with the actual error details) is lost in the middle of a ton of junk, making it unnecessarily hard to extract.

To Reproduce Run a query with an error, e.g. with reference to an unknown identifier.

Expected behavior CosmosException.ResponseBody should contain the actual response body returned by Cosmos DB, i.e. something like this:

{"errors":[{"severity":"Error","location":{"start":36,"end":48},"code":"SC2001","message":"Identifier 'foo' could not be resolved."}]}

Actual behavior CosmosException.ResponseBody returns something that looks like the result of calling ToString() on an exception:

Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException: TryCatch resulted in an exception. ---> Microsoft.Azure.Cosmos.Query.Core.Monads.ExceptionWithStackTraceException: TryCatch resulted in an exception. ---> Microsoft.Azure.Cosmos.Query.Core.Exceptions.ExpectedQueryPartitionProviderException: {"errors":[{"severity":"Error","location":{"start":36,"end":48},"code":"SC2001","message":"Identifier 'foo' could not be resolved."}]}
 ---> System.Runtime.InteropServices.COMException (0x800A0B00): 0x800A0B00
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Cosmos.Query.Core.QueryPlan.QueryPartitionProvider.TryGetPartitionedQueryExecutionInfoInternal(SqlQuerySpec querySpec, PartitionKeyDefinition partitionKeyDefinition, Boolean requireFormattableOrderByQuery, Boolean isContinuationExpected, Boolean allowNonValueAggregateQuery, Boolean hasLogicalPartitionKey)
  (... long stack trace...)

   --- End of inner exception stack trace ---
   at Microsoft.Azure.Cosmos.Query.Core.QueryPlan.QueryPartitionProvider.TryGetPartitionedQueryExecutionInfo(SqlQuerySpec querySpec, PartitionKeyDefinition partitionKeyDefinition, Boolean requireFormattableOrderByQuery, Boolean isContinuationExpected, Boolean allowNonValueAggregateQuery, Boolean hasLogicalPartitionKey)
   (... long stack trace...)

This is utterly unusable and doesn’t help anyone.

Environment summary SDK Version: 3.13.0 OS Version: Windows 10

Additional context N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ealsurcommented, Apr 8, 2022

The issue seems to be related to: https://github.com/Azure/azure-cosmos-dotnet-v3/blob/master/Microsoft.Azure.Cosmos/src/Query/Core/QueryPlan/QueryPlanRetriever.cs#L77-L81

The innerException is not getting populated when creating the BadRequest exception on the query plan.

1reaction
thomaslevesquecommented, Oct 7, 2020

BTW, in case you’re wondering why I need to be able to parse the error, it’s because I’m working on a tool for querying and managing Cosmos databases. I’d like to be able to display more user-friendly error messages to the user.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Azure Cosmos DB bad request exceptions
A response with this error means you are executing an operation and passing a partition key value that does not match the document's...
Read more >
Response status code does not indicate success when ...
I get following error that does not provide much information? Microsoft.Azure.Cosmos.CosmosException: 'Response status code does not indicate ...
Read more >
CosmosException.ResponseBody Property
The body of the cosmos response message as a string.
Read more >
Response Body does not show detail stack trace of ...
Hi, I am sending some array of data to service and it is expected to throw SQL exception. In my application I am...
Read more >
Should a REST API return a 500 Internal Server Error to ...
The response body SHOULD include enough information for the user to recognize the source of the conflict. Ideally, the response entity would ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found