CosmosException.ResponseBody doesn't actually contain the response body
See original GitHub issueDescribe 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:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top GitHub Comments
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.
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.